当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

技术分享 | 实战详解接口测试请求方式Get、post

redis缓存设计与性能优化
![[explain in detail how to realize Sanzi chess step by step]](/img/17/68ef51ec2be0c86019461116ecaa82.png)
[explain in detail how to realize Sanzi chess step by step]

中国剩余定理 个人理解

项目编译NoSuch***Error问题

Water drop effect on umbrella

Two dimensional array practice: spiral matrix

NFT data storage blind box + mode system development

prometheus监控nacos

Skimming records -- sequence traversal of binary tree
随机推荐
软件测试(概念篇)
[C note] data type and storage
[C language] dynamic memory management
How to simulate the implementation of strcpy library functions
[pta ---- traversal of tree]
Elastic common high frequency commands
战疫杯--我的账本
Rain Scene Effect (I)
Leetcode 刷题日记 剑指 Offer II 053. 二叉搜索树中的中序后继
数组转链表
NFT data storage blind box + mode system development
OJ 1131 beautiful number
js 变量等于0也等也' '问题
Everything you don't know about time complexity is here
AQS之ReentrantLock源码解析
代码整洁之道(二)
Mongodb replica set and partitioned cluster
Yapi vulnerability hanging horse program chongfu.sh processing
准备开始写博客了
RayMarching实现体积光渲染