P1304 godebach conjecture, p1304 godebach Conjecture
Description
Input N (N <= 10000), verify 4 ~ N: whether all the even numbers comply with the godebach conjecture.
(N is an even number ).
If a number is used, for example, 10, the first addition number is output, which is the smallest solution compared to other solutions. For example, 10 = 3 + 7 = 5 + 5, 10 = 5 + 5 is the incorrect answer.
Input/Output Format
Input Format:
First line N
Output Format:
4 = 2 + 2 6 = 3 + 3 ...... N = x + y
Input and Output sample input sample #1:
10
Output sample #1:
4 = 2 + 26 = 3 + 38 = 3 + 510 = 3 + 7
First screen one side of prime number,
Then the brute-force enumeration is good.
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 using namespace std; 7 const int MAXN=10001; 8 const int maxn=0x7fffff; 9 void read(int &n)10 {11 char c='+';int x=0;bool flag=0;12 while(c<'0'||c>'9')13 {c=getchar();if(c=='-')flag=1;}14 while(c>='0'&&c<='9')15 {x=x*10+(c-48);c=getchar();}16 flag==1?n=-x:n=x;17 }18 int n;19 int vis[MAXN];20 int main()21 {22 read(n);23 vis[1]=1;24 for(int i=2;i<=n;i++)25 if(!vis[i])26 for(int j=i*i;j<=n;j+=i)27 vis[j]=1;28 for(int i=4;i<=n;i+=2)29 for(int j=2;j<=n;j++)30 if(vis[j]==0&&vis[i-j]==0)31 {32 printf("%d=%d+%d\n",i,j,i-j);break;33 }34 35 return 0;36 }