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 |
Re:AC了,代码如下, 这道题目不难In Reply To:Re:AC了,代码如下, 这道题目不难 Posted by:qdenis at 2009-03-16 09:16:11 #include <iostream> #include <math.h> using namespace std; bool isprime(int x) { int i; double m=sqrt((double)x); for(i=2;i<=m;i++) if(x%i==0) return false; return true; } int main() { int n,i; while(cin>>n && n) { bool flag=false; for(i=3;i<=n/2;i+=2) if(isprime(i) && isprime(n-i)) { flag=true; break; } if(flag) cout<<n<<" = "<<i<<" + "<<n-i<<endl; else cout<<"Goldbach's conjecture is wrong."<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator