POJ2739 Sum of Consecutive Prime Numbers
来源:互联网 发布:php学习手册 编辑:程序博客网 时间:2024/05/04 02:29
题目大意:给出一个数n,判断n是否可以被连续质数的和表示,可以的话,输出可能的情况总数。输入以0结束。
#include <iostream>using namespace std;#define max_n 10010int prime[max_n];int pcnt;bool notprime[max_n];void initprime(int n){pcnt=0;for(int i=2;i<=n;i++){if(!notprime[i]){prime[pcnt++]=i;for(int j=i+i;j<=n;j+=i)notprime[j]=true;}}}int n;int cnt;int main(){initprime(10000);while(scanf("%d",&n),n){cnt=0;for(int i=0;i<pcnt;i++){int sum=0;for(int j=i;j<pcnt&&sum<n;j++ )//sum=n,就会多循环一次{sum+=prime[j];}if(sum==n) cnt++;}printf("%d\n",cnt);}return 0;}
0 0
- POJ2739 Sum of Consecutive Prime Numbers
- POJ2739 Sum of Consecutive Prime Numbers
- POJ2739--Sum of Consecutive Prime Numbers
- POJ2739-Sum of Consecutive Prime Numbers
- poj2739 Sum of Consecutive Prime Numbers 杂题
- [POJ2739]Sum of Consecutive Prime Numbers
- POJ2739-Sum of Consecutive Prime Numbers
- poj2739 Sum of Consecutive Prime Numbers
- POJ2739 Sum of Consecutive Prime Numbers
- POJ2739-Sum of Consecutive Prime Numbers
- POJ2739 Sum of Consecutive Prime Numbers
- poj2739 - Sum of Consecutive Prime Numbers(求素数)
- POJ2739 Sum of Consecutive Prime Numbers素数打表
- POJ2739---Sum of Consecutive Prime Numbers(尺取法)
- POJ2739--Sum of Consecutive Prime Numbers(尺取法)
- poj2739 Sum of Consecutive Prime Numbers (素数打表)
- POJ2739-Sum of Consecutive Prime Numbers【尺取法】
- POJ2739:Sum of Consecutive Prime Numbers(简单数论)
- Windows下的VMware下的Centos7.2静态IP配置
- 二、关于HDFS、YARN及MapReduce的理解
- 最优分解问题
- Lowest Common Ancestor of a Binary Tree
- Unity工程中 .Meta 文件的作用
- POJ2739 Sum of Consecutive Prime Numbers
- 文章标题
- 最优合并问题
- 网络通信过程 及TCP/UDP 面向连接?
- dlgdata.cpp line 40 error
- sublime text怎么显示及修改侧边栏颜色
- 常用正则表达式
- Big Data Processing:Map and Reduce
- 网络5层协议描述