《数据结构编程实验》 1.2.2Sum of Consecutive Prime Numbers
来源:互联网 发布:卡巴斯基软件下载 编辑:程序博客网 时间:2024/06/06 01:33
题目大意:
给出一个正整数,求将它用连续素数和的形式来表示的方案数。
题目地址:
POJ 2739 UVA 3399
题解:
初始化一份素数表,对给出的正整数,枚举每个方案的初始素数。
#include <iostream>#include <cstdio>using namespace std;int PrimeScreen(int a[],int &n){ int f[10010]; int i,j; for (i=2;i<=10000;i++) f[i]=1; for (i=2;i*i<10000;i++) if (f[i]) for (j=i*i;j<10000;j+=i) f[j]=0; for (i=2;i<10000;i++) if (f[i]) {a[n]=i;n++;} return 0;}int main(){ int a[2000]; int n; int i,j,k; int m,ans; n=0; PrimeScreen(a,n); while (scanf("%d",&m)&&m) { ans=0; for (i=0;i<n;i++) { j=a[i]; k=i+1; while (j<m&&k<n) {j=j+a[k];k++;} if (j==m) ans++; } printf("%d\n",ans); } return 0;}
0 0
- 《数据结构编程实验》 1.2.2Sum of Consecutive Prime Numbers
- C - Sum of Consecutive Prime Numbers(1.2.2)
- C - Sum of Consecutive Prime Numbers(1.2.2)
- C - Sum of Consecutive Prime Numbers(1.2.2)
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers pku 2739
- POJ2739 Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- Wakelocks: Detect No-Sleep Issues in Android* Applications(转载)
- C++-指针详解(2)
- MySQL数据库MyISAM和InnoDB存储引擎的比较
- POJ 1321----棋盘问题(深搜)
- 关于c++ 程序 哪个文件可以复制到其他电脑上运行
- 《数据结构编程实验》 1.2.2Sum of Consecutive Prime Numbers
- android radiobutton 设置文本为空 button属性居中效果
- 开发第一个Hibernate
- 【bzoj3196】二逼平衡树【树套树】【线段树】【平衡树】【呵呵】
- 项目执行maven update时,报:Preference node "org.eclipse.wst.validation"...
- A - The Hardest Problem Ever(字符串模拟题)
- 绝对值排序
- OC中的排序算法
- 辛星浅析lvm