UVA1210Sum of Consecutive Prime Numbers(素数打表 + 连续和)
题意:输入一个数n (2 <= n <= 10000) 有多少种方案可以把n写成若干个连续素数之和
打出10000之内的素数表,然后再打出每个可能得到的和的方案数的表
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int Max = ;
int prime[Max + ],total,flag[Max + ];
int dp[]; //可以求出10000所有素数和为5000000多
void get_prime()
{
memset(flag, , sizeof(flag));
total = ;
for(int i = ; i <= Max; i++)
{
if(flag[i] == )
{
prime[ ++total ] = i;
for(int j = i; j <= Max / i; j++)
flag[i * j] = ;
}
}
}
void init()
{
memset(dp, , sizeof(dp));
int ans;
for(int i = ; i <= total; i++)
{
ans = ;
for(int j = i; j <= total; j++) //第i个为起点,第j个为终点的素数段
{
ans += prime[j];
dp[ans]++;
}
}
}
int main()
{
get_prime();
init();
int n;
while(scanf("%d", &n) != EOF && n)
{
printf("%d\n", dp[n]);
}
return ;
}
UVA1210Sum of Consecutive Prime Numbers(素数打表 + 连续和)的更多相关文章
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- CodeForces 385C Bear and Prime Numbers 素数打表
第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...
- UVA 10539 - Almost Prime Numbers 素数打表
Almost prime numbers are the non-prime numbers which are divisible by only a single prime number.In ...
- Sum of Consecutive Prime Numbers(素数打表+尺取)
Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
- POJ2739_Sum of Consecutive Prime Numbers【筛法求素数】【枚举】
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19350 Ac ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- Android手机截屏
刚开始打算做一个简单的截屏程序时,以为很轻松就能搞定. 在Activity上放一个按钮,点击完成截屏操作,并将数据以图片形式保存在手机中. 动手之前,自然是看书和网上各种查资料.结果发现了解的知识越多 ...
- UITextView的使用详解
//初始化并定义大小 UITextView *textview = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, 280, 30)]; te ...
- Ubuntu下安装IDA pro
预备 由于IDA pro只能装在32位环境下,如果是64位Ubuntu,需要运行如下命令安装32位的必备库. sudo dpkg --add-architecture i386 sudo apt-ge ...
- iOS开发小技巧--UIButton的另一种布局方法(第一种在layoutSubViews方法中,这一种利用苹果提供的两个返回CGRect的方法)
- git 常用命令使用
1. 初始化仓库 git init 2. 查看当前状态 git status(1)Changes not staged for commit:(2)Changes to be committed: 3 ...
- javascript 红宝书笔记之操作日期
创建当日 日期对象 调用Date的构造函数而不传递参数的情况下,新创建的对象默认获取当前的日期和时间. var now = new Date(); 创建特定的日期和时间对象 Date. ...
- python 进程间共享数据 (二)
Python中进程间共享数据,除了基本的queue,pipe和value+array外,还提供了更高层次的封装.使用multiprocessing.Manager可以简单地使用这些高级接口. Mana ...
- 提示reg不是批处理命令怎么办
'regsvr32' 不是内部或外部命令,也不是可运行的程序或批处理文件.请按任意键继续. . . 系统环境变量被改了进入控制面板>高级>环境变量>系统变量,Path双击一下,填入C ...
- 系统间通信(5)——IO通信模型和JAVA实践 下篇
7.异步IO 上面两篇文章中,我们分别讲解了阻塞式同步IO.非阻塞式同步IO.多路复用IO 这三种IO模型,以及JAVA对于这三种IO模型的支持.重点说明了IO模型是由操作系统提供支持,且这三种IO模 ...
- shell中逻辑与的两种表示方法
bash中表示逻辑与的两种方法: (1)[ $state == "running" -a $name == "zone1" ] (2)[[ $state == ...