| ||||||||||
| 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:用scanf printf就对的,用cin cout就错了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator