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:AC了,代码如下, 这道题目不难 Posted by:382784268 at 2009-03-07 12:53:31 > #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