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<iostream> using namespace std; int isprime(int num) { for(int i=2;i*i<=num;i++) if(num%i==0) return 0; return 1; } int main() { int m; while(cin>>m&&m) { for(int i=2;i<=m/2;i++) if(isprime(i)&&isprime(m-i)) { cout<<m<<" = "<<i<<" + "<<m-i<<endl; break; } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator