当前位置:Gxlcms >
数据库问题 >
POJ 2262 Goldbach's Conjecture 数学常识 难度:0
POJ 2262 Goldbach's Conjecture 数学常识 难度:0
时间:2021-07-01 10:21:17
帮助过:3人阅读
#include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 using namespace std;
5 const int maxn = 1e6 +
6;
6 int n;
7 bool ntp[maxn];
8 int prime[maxn],cnt;
9 void judgeprime()
10 {
11 for(
int i =
3;i < maxn;i +=
2)
12 {
13 if(ntp[i])
continue;
14 prime[cnt++] =
i;
15 for(
int j =
3;j * i < maxn;j +=
2)
16 {
17 ntp[i * j] =
true;
18 }
19 }
20
21 }
22
23 int main()
24 {
25 judgeprime();
26 while(scanf(
"%d",&n)==
1 &&
n)
27 {
28 for(
int i =
0;i < cnt && i < n /
2;i++
)
29 {
30 if(!ntp[n -
prime[i]])
31 {
32 printf(
"%d = %d + %d\n",cnt,prime[i],n -
prime[i]);
33 break;
34 }
35 }
36 }
37 return 0;
38 }
View Code
POJ 2262 Goldbach's Conjecture 数学常识 难度:0
标签: