简单的素数打表,然后枚举。开始没注意n读到0结束,TLE了回。。下次再认真点。A过后讨论里面有个暴力打表过的,给跪了!
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <complex.h>
#include <cmath>
using namespace std; const int N = ; bool is[N]; int prm[N];
int getprm (int n) {
int i, j, k = ;
int s, e = (int)(sqrt(0.0 + n) + );
memset (is, , sizeof (is));
prm[k ++] = ; is[] = is[] = ;
for (i = ; i < n; i += ) is[i] = ;
for (i = ; i < e; i += )
if (is[i]){
prm[k ++] = i;
for (s = i * , j = i * i; j < n; j += s) {
is[j] = ;
}
}
for (; i < n; i += ) {
if (is[i]) prm[k ++] = i;
}
return k;
} int main () {
getprm();
/*for (int i = 0 ; i < 100; ++ i) {
cout << i << ": ";
cout << prm[i] << endl;
}*/
// 1229个素数 0-1w
ios::sync_with_stdio(false);
cin.tie();
int n;
while (~scanf ("%d", &n)) {
if (n == ) break;
int sum, cnt = ;
for (int i = ; prm[i] <= n; ++ i) {
sum = ;
for (int j = i; prm[j] <= n; ++ j) {
sum += prm[j];
if (sum < n) {
continue;
} else if (sum == n) {
cnt ++;
break;
} else {
break;
}
}
}
printf ("%d\n", cnt);
}
return ;
}