当前位置:网站首页>PKU-2739-Sum of Consecutive Prime Numbers(筛素数法打表)
PKU-2739-Sum of Consecutive Prime Numbers(筛素数法打表)
2022-07-28 05:28:00 【__Simon】
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 23390 | Accepted: 12780 |
Description
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.
Your mission is to write a program that reports the number of representations for the given positive integer.
Input
Output
Sample Input
2 3 17 41 20 666 12 53 0
Sample Output
1 1 2 3 0 0 1 2
Source
#include <stdio.h>
#define MAX 10000
int a[MAX+10];
void isPrime(){//一种比较高效的筛素数法
int i,j;
for(i=2;i*i<=MAX;i++)
if(a[i]==0)
for(j=i+i;j<=MAX;j += i)
a[j]=1;
}
int main() {
int n,i,j,sum,k;
isPrime();
while(scanf("%d",&n)&&n!=0){
k=0;
for(i=2;i<=n;i++){
sum=0;
if(a[i]==0)
for(j=i;;j++){
if(a[j]==0)
sum+=j;
if(sum>n)
break;
else if(sum==n){
k++;
break;
}
}
}
printf("%d\n",k);
}
return 0;
}
边栏推荐
猜你喜欢

explain详解

AQS之semaphore源码分析

archery数据库审核平台部署

下雨场景效果(一)

Graphic pipeline foundation (part outside)

Leetcode brush question diary sword finger offer II 053. Medium order successor in binary search tree

Redis implementation of distributed lock and analysis of the main process of redismission distributed lock
![[pta ---- traversal of tree]](/img/d8/260317b30d624f8e518f8758706ab9.png)
[pta ---- traversal of tree]

Skimming records -- sequence traversal of binary tree
![Implementation of simple address book in [c language]](/img/75/8f2f4dd1c166808047cda6bea5a746.png)
Implementation of simple address book in [c language]
随机推荐
[C language] custom structure type
@Postconstruct annotations and useful examples
思寒漫谈测试人职业发展
NiO example
Problem solving for ACM freshmen in Jiangzhong on October 26
进程和线程的区别
mongo ssl 配置实战
Mongodb replica set and partitioned cluster
订单交易简析
数组转链表
什么是线性表?
代码整洁之道(一)
测试面试题集锦(五)| 自动化测试与性能测试篇(附答案)
elastic常用高频命令
OJ 1242 大一上之初出茅庐
Analysis of the semaphore source code of AQS
水瓶效果制作
从普通查询商品到高并发查询商品的优化思路
Leetcode brush question diary sword finger offer II 048. serialization and deserialization binary tree
SSAO by computer shader (II)