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

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

Posted by ambition0109 at 2010-07-04 10:34:29 on Problem 2739
In Reply To:用scanf printf就对的,用cin cout就错了 Posted by:ambition0109 at 2010-06-29 14:27:17
>这个就AC... 

#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(scanf("%d",&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;
>                         }
>                 }
>                 printf("%d\n",count);
>         }
>         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