标签:
又水,素数只能是连续的,而且最多才10000!
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 int a[10001]; 6 7 bool is_prime(int x) 8 { 9 if(x == 1) return 0; 10 for(int i=2; i*i<=x; i++) 11 if(x % i == 0) 12 return 0; 13 return 1; 14 } 15 16 int get_prime() 17 { 18 int count=0; 19 for(int i=2; i<10000; i++) 20 { 21 if(is_prime(i)) 22 a[count++]=i; 23 } 24 return count; 25 } 26 27 int main() 28 { 29 int num; 30 int count = get_prime(); 31 while(scanf("%d", &num) != EOF, num) 32 { 33 34 int ans=0; 35 for(int i=0; i<count; i++) 36 { 37 int sum=0; 38 int j=i; 39 while(sum < num) 40 { 41 sum+=a[j++]; 42 //cout << "sum: " <<sum << endl; 43 if(sum == num) 44 { 45 ans++; 46 break; 47 } 48 } 49 50 } 51 cout << ans << endl; 52 } 53 return 0; 54 }
sicily 1259 Sum of Consecutive Primes
标签:
原文地址:http://www.cnblogs.com/dominjune/p/4547502.html