当前位置:网站首页>Pku-2739-sum of constructive prime numbers
Pku-2739-sum of constructive prime numbers
2022-07-28 06:51: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(){// A more efficient method of sifting prime numbers
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;
}
边栏推荐
- 思寒漫谈测试人职业发展
- [C language] custom structure type
- Graphic pipeline foundation (I)
- 代码整洁之道(二)
- CentOS7部署MySQL数据库服务器
- Dynamic memory management function of C language
- Question brushing record -- binary tree
- redis实现分布式锁思路及redission分布式锁主流程分析
- Leetcode brush question diary sword finger offer II 048. serialization and deserialization binary tree
- How to simulate the implementation of strcpy library functions
猜你喜欢

Lancher deployment practice

JS reverse question 100 - question 1

What is the good brand of air conduction Bluetooth headset and the best brand recommendation of air conduction headset

Redis cache design and performance optimization

技术分享 | 使用 cURL 发送请求
![[c language] - step by step to achieve minesweeping games](/img/ee/49ddfcd948ccd5c8c9dec3c48c6112.png)
[c language] - step by step to achieve minesweeping games

【无标题】

Battle plague Cup -- strange shape

Dynamic memory management function of C language

Yapi vulnerability hanging horse program chongfu.sh processing
随机推荐
Graphic pipeline foundation (part outside)
软件开发中常见模型
[pta---- output full arrangement]
Personal understanding of Chinese remainder theorem
SSAO by computer shader (I)
Array solution script
Code neatness (2)
mysql-8.0.17-winx64(附加navicat)手动配置版安装
archery数据库审核平台部署
等保3.0-服务器三权分立配置
AQS之ReentrantLock源码解析
Analysis of the semaphore source code of AQS
测试人生 | 二线城市年薪超40W?疫情之下涨薪100% + 是怎么做到的?
技术分享 | 实战详解接口测试请求方式Get、post
Dynamic memory management function of C language
遍历 二叉树
HDU-2036-改革春风吹满地(多边形面积模板)
[dynamic planning -- the best period for buying and selling stocks Series 2]
思寒漫谈测试人职业发展
技术分享 | 接口自动化测试中,如何做断言验证?