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<stdio.h> int gen(int n); int prime(int n); int main() { int n; while(scanf("%d",&n)&&n!=0) printf("%d\n",gen(n)); return 0; } int gen(int n) { int i,count=0; for(i=2;i<=n/2;i++) if(prime(i)&&prime(n-i)) count++; return count; } int prime(int n) { int i; for(i=2;i<=n/2;i++) if(n%i==0) return 0;; return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator