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 |
AC了,代码如下, 这道题目不难#include<iostream> #include<cmath> using namespace std; int isprime(int a) { int flag=1; int i; for(i=2;i<=sqrt(double(a));i++) { if(a%i==0) { flag=0; break; } } return flag; } void result( int n,int *a) { int i; for(i=3;i<=n/2;i=i+2) { int flag=0; if(isprime(i)) { flag++; } else continue; if(isprime(n-i)) { flag++; } else continue; if(flag==2) { *a=i; break; } } } int main() { int n; while(cin>>n&&n) { int a; result(n,&a); cout<<n<<" = "<<a<<" + "<<n-a<<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