Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
注意打素数表,用筛选法。#include <cstring> #include <cstdio> #include <cmath> using namespace std; int v[1005],t,n,x1,x2; bool d[1000005]; void prime() { memset(d,1,sizeof(d)); int k,i,j;bool p; v[++t]=2; for(i=3;i<=1000;i+=2) { k=sqrt(i);p=1; for(j=3;j<=k;j+=2) { if(i%j==0) { p=false; break; } } if(p)v[++t]=i; } for(i=3;i<=1000000;i+=2) { for(j=1;j<=t;j++) { if(v[j]>=i)break; if(i%v[j]==0) { d[i]=false; break; } } } } int main() { prime(); while(scanf("%d",&n)&&n) { x1=3; while(1) { x2=n-x1; if(d[x1]&&d[x2]) { printf("%d = %d + %d\n",n,x1,x2); break; } x1+=2; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator