Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求 帮忙检查下代码 哪里有问题

Posted by zhyu388 at 2014-05-09 20:19:53 on Problem 2739
#include<cstdio>
#include<cstring>
int n;
int a[10010],b[10010];
void shu()
{
    memset(a,0,sizeof(a));
    for(int i=2;i<=10010;i++)
    {
        if(a[i]==0)
        {
            for(int j=2;j*i<=10010;j++)
            a[j*i]=1;
        }
    }
}
int main()
{
    shu();
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
        break;
        int t=0,cnt=0,k,ans=0;
        for(int i=2;i<=n;i++)
        {
            if(a[i]==0)
            b[t++]=i;
        }
        for(int i=0;i<t;i++)
        {
            k=i;
            while(cnt<=n)
            {
                cnt=cnt+b[k++];
                if(cnt==n)
                {
                    ans++;
                    cnt=n+1;
                }
            }
            cnt=0;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator