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 |
其实这道题感觉可以和2140类比,我的是先建立一个查询表,再直接搜In Reply To:做了好多关于素数的题,这个算是比较综合的,呵呵~~~~ Posted by:xiaoyuanwang at 2007-05-04 16:27:23 #include<stdio.h> #include<math.h> long p[1500][1500]; bool is_prime(long n) { long i; for(i=2;i<=sqrt(n);i++) if(n%i==0) return 0; return 1; } void build_p() { int i,j; int step=1; for(i=2;step<1500&&i<=20000;i++) if(is_prime(i))p[1][step++]=i; for(i=2;i<1300;i++) for(j=1;j<1300;j++) p[i][j]=p[i-1][j]+p[1][i+j-1]; } void solve(int n) { int cnt,i,j; i=j=1; cnt=0; for(i=1;i<1300;i++) for(j=1;j<1300;j++) if(p[i][j]==n)cnt++; printf("%d\n",cnt); } int main() { int n; build_p(); while(scanf("%d",&n),n!=0) solve(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