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:帮忙看下怎么会超时呢In Reply To:Re:帮忙看下怎么会超时呢 Posted by:zhuangzebo at 2011-04-14 13:32:33 #include<stdio.h> int prime(int k){ int flag=1; int j; for(j=2;j*j<=k;j++){ //这样就不会了... if(k%j==0){ flag=0; break; } } return flag; } int main(){ int i,n,f=0; for(scanf("%d",&n);n!=0;scanf("%d",&n)){ f=0; for(i=3;i<=n/2;i=i+2){ if(prime(i)&&prime(n-i)){ printf("%d = %d + %d\n",n,i,n-i); f=1; break; } } if(!f) printf("Goldbach's conjecture is wrong.\n"); } return (0); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator