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

用scanf printf就对的,用cin cout就错了

Posted by ambition0109 at 2010-06-29 14:27:17 on Problem 2739
#include<iostream>
using namespace std;

bool prime[10000];
int main()
{
        int i,j;
        memset(prime,true,sizeof(prime));
        for(i=2;i<100;i++)
        {
                if(prime[i])
                {
                        for(j=i*i;j<10000;j+=i)
                                prime[j]=false;
                }
        }
        int n,sum,count;
        while(cin>>n,n)
        {
                for(i=2,count=0;i<=n;i++)
                {
                        if(!prime[i]) continue;
                        for(j=i,sum=0;j<=n;j++)
                        {
                                if(!prime[j]) continue;
                                sum+=j;
                                if(sum<n) continue;
                                else if(sum==n)
                                {
                                        count++;
                                        break;
                                }
                                else break;
                        }
                }
                cout<<count<<endl;
        }
        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