| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为啥我数组范围开到12000反而不行?10001就能AC#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 10005
int prim[maxn] = { 0 };
int num[maxn];
int count = 0;
void init()
{
for (int i = 2; i*i <= maxn; i++)
{
if (!prim[i])
{
for (int j = i*i; j <= maxn; j += i)
prim[j] = 1;
}
}
for (int i = 2; i <= maxn; i++)
if (!prim[i])
num[count++] = i;
}
int main()
{
init();
int n;
while (scanf("%d", &n), n)
{
int ans = 0;
for (int i = 0; i < count; i++)
{
int sum = 0;
for (int j = i;; j++)
{
sum += num[j];
if (sum == n)
{
ans++;
break;
}
if (sum > n)
break;
}
if (num[i] >= n)
break;
}
printf("%d\n", ans);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator