题意简述:给定一个n,如果n可以表示为连续的素数和,求出有多少种这样不同的表示。
先筛一遍素数,然后尺取记录就可以啦~
code:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO \
ios::sync_with_stdio(false); \
// cin.tie(0); \
// cout.tie(0);
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 11092019;
int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
int a[maxn];
bool isprime[maxm]; //若1为素数 若0不是素数
int su[maxm];
int cnt = 0;
void prime()
{
memset(isprime, true, sizeof isprime);
memset(su, 0, sizeof su);
isprime[0] = isprime[1] = false; // 0 和 1 不是素数
for (int i = 2; i <= maxm; i++)
{
if (isprime[i])
su[++cnt] = i;
for (int j = 1; j <= cnt && i * su[j] <= maxm; j++)
{
isprime[i * su[j]] = false;
if (i % su[j] == 0)
break;
}
}
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
IO;
int T;
int n, s;
prime();
// for (int i = 1; i <= 25; i++)
// cout << su[i] << endl;
// cout << cnt << endl;
while (scanf("%d", &n) == 1 && n)
{
int L = 1;
int R = 1;
int ans = 0;
int t = su[1];
while (L <= cnt && R <= cnt)
{
if (t >= n)
{
if (t == n)
ans++;
t -= su[L];
++L;
}
else
{
++R;
t += su[R];
}
}
cout << ans << endl;
}
return 0;
}