#28620: 為什麼這樣會RE


kevin010411@gmail.com (傅詳閎)

學校 : 元智大學
編號 : 94708
來源 : [114.34.25.112]
最後登入時間 :
2024-09-17 16:52:38
d362. 10394 - Twin Primes -- UVa10394 | From: [114.43.51.186] | 發表日期 : 2021-12-22 10:44

#include <iostream>

#include <vector>

#include <cmath>

 

using namespace std;

 

const int MAX = 20000001;

 

int p[MAX];

 

int main()

{

p[0] = 1;

p[1] = 1;

for (int i = 2; i < sqrt(MAX); ++i)

{

for (int k = (MAX - 1) / i, j = k * i; k >= i; --k, j-=i)

{

if (!p[k])

p[j] = 1;

}

}

vector <int> prime;

for (int i = 2; i < MAX; ++i)

{

if (!p[i])

{

prime.push_back(i);

}

}

vector <vector <int> > ans;

for (int i = 0; i < prime.size() - 2; ++i)

{

if (prime[i] + 2 == prime[i + 1])

{

vector <int> temp;

temp.push_back(prime[i]);

temp.push_back(prime[i + 1]);

ans.push_back(temp);

}

}

int S;

while (cin >> S)

{

--S;

cout << "(" << ans[S][0] << ", " << ans[S][1] << ")\n";

}

}

 
ZeroJudge Forum