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

打表飘过。。数组开1229,别开小了!!!

Posted by qibinlou at 2012-08-10 17:22:26 on Problem 2739
#include<iostream>
#include<cmath>
using namespace std;
const int Max=1229;
int a[Max];
int isprime(int x)
{   
	if(x==1) return 0;
 	if(x==2) return 1;
 	if(x%2==0) return 0;
    int i;
    for(i=3;i<=sqrt(x);i+=2)
      if(x%i==0) return 0;
    return 1;
}


int main()
{
    int i,j,sum,count,n;
      for(i=2,j=0;i<10000;i++)
      if(isprime(i)==1)
        a[j++]=i;
    //    cout<<j<<' '<<a[j-1]<<endl;
    while(cin>>n,n!=0){
    
     for(i=count=0;i<Max;i++){
      for(j=i,sum=0;j<Max && sum<n;j++)
        sum+=a[j];
      if(sum==n)
         count++;
    
     }
      cout<<count<<endl;
    }

  // system("pause");
} 

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