# 北大ACM2739——Sum of Consecutive Prime Numbers

#include <iostream>
using namespace std;

int prime[10005];

int main()
{
int i, j, k;
for(i = 0; i < 10005; i++)
prime[i] = 1;
prime[0] = 0; prime[1] = 0;
for(i = 2; i < 10005; i++)                //判断10005以内的所以素数。
{
if(prime[i])
{
for(j = i + i; j < 10005; j += i)
prime[j] = 0;
}
}
int count, sum;
while(cin >> k && k)
{
for(i = 2, count = 0; i < 10005; i++)           //找有多少组
{
if(!prime[i])
continue;
for(j = i, sum = 0; sum < k && j < 10005; j++)
{
if(prime[j])
sum += j;
if(sum == k)
{
count++;
break;
}
}
}
cout << count << endl;
}
return 0;
}

• 本文已收录于以下专栏：

## poj2739 Sum of Consecutive Prime Numbers （素数打表）

D - Sum of Consecutive Prime Numbers Crawling in process... Crawling failed Time Limit:1000MS    ...

## POJ 2739 Sum of Consecutive Prime Numbers（线性素数筛+前缀和）

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: ...

## POJ 2739 - Sum of Consecutive Prime Numbers(素数筛法+前缀和 / 尺取法)

Description Some positive integers can be represented by a sum of one or more consecutive prime num...

## poj 2739 Sum of Consecutive Prime Numbers（尺取，暴力）

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Sub...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)