标签:
#include <cstdio> int isPrime(int n) { int i; if(n == 1) return 0; for(i = 2; i*i <= n; ++i) if(n%i == 0) return 0; return 1; } int main() { int n,result,j,i,sum; while(scanf("%d",&n) && n) { result = sum = 0; for(i = 2; i <= n; ++i) { if(isPrime(i)) { sum = 0; for(j = i; j <= n; ++j) { if(isPrime(j)) { sum += j; if(sum == n) { ++result; break; } if(sum > n) break; } } } } printf("%d\n",result); } return 0; }
poj 2739 Sum of Consecutive Prime Numbers
标签:
原文地址:http://www.cnblogs.com/guoyongheng/p/5721771.html