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 |
筛选加暴力 16MS#include <stdio.h> int main () { int a[10001]; int temp;int k=0;int i;int sum;int n; int b[10000]; int flag;int num; for (i=2;i<=10000;i++) a[i]=1; for (i=2;i<=5000;i++) { if (a[i]==1) { temp=2*i; while (temp<=10000) { a[temp]=0; temp+=i; } } } for (i=2;i<10001;i++) if (a[i]==1) b[++k]=i; while (EOF!= scanf("%d",&n)) { if (n==0) break; flag=1;num=0; while (b[flag]<=n) { sum=0; for (i=flag;;i++) { sum=sum+b[i]; if (sum==n) { num++;break;} if (sum>n) break; } flag++; } printf("%d\n",num); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator