| ||||||||||
| 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:0MS 标准的c语言写的... 不容易啊...In Reply To:0MS 标准的c语言写的... 不容易啊... Posted by:songsuoyuan at 2009-05-10 09:54:56 > #include<stdio.h>
>
> int a[10010];
> int b[1229];
>
> void createprime()
> {
> int i,j;
> for(i=2;i<10010;i++){
> if(a[i]==1)
> continue;
> for(j=2;i*j<10010;j++)
> a[i*j]=1;
> }
> j=0;
> for(i=2;i<10010;i++)
> if(a[i]==0){
> b[j]=i;
> j++;
> }
> }
>
> int main()
> {
> createprime();
> int work,i,j,sum,p;
> while(1){
> scanf("%d",&work);
> if(work==0)
> break;
> p=0;
> for(i=0;b[i]<=work;i++){
> j=i;
> sum=0;
> while(1){
> sum+=b[j];
> if(sum==work){
> p++;
> break;
> }
> if(sum>work)
> break;
> j++;
> }
> }
> printf("%d\n",p);
> }
> return 0;
> }
素数的倍数就不用考虑吗?
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator