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 ...
随机推荐
- 使用docker发布spring cloud应用
本文涉及到的项目: cloud-simple-docker:一个简单的spring boot应用 Docker是一种虚拟机技术,准确的说是在linux虚拟机技术LXC基础上又封装了一层,可以看成是基于 ...
- Bash on Windows 抢鲜测试 -- 介绍及安装
前言 微软在上周的Windows BUILD大会上宣布,WIN10将引入原生Bash,并将很快在技术预览版中推出. 如此一来,windows的命令行工具就不再只有cmd和powershell了,我们可 ...
- HBase初探
string hbaseCluster = "https://charju.azurehdinsight.net"; string hadoopUsername = "账 ...
- WEB API 中HTTP的get、post、put,delete 请求方式
一.WEB API 中HTTP 请求方式的四个主要方法 (GET, PUT, POST, DELETE), 按照下列方式映射为 CURD 操作: 1.POST 用于新建资源,服务端在指定的URI 上创 ...
- c#自动关闭 MessageBox 弹出的窗口
我们都知道,MessageBox弹出的窗口是模式窗口,模式窗口会自动阻塞父线程的.所以如果有以下代码: MessageBox.Show("内容',"标题"); 则只有关闭 ...
- 既不删除, 也不生成DS_store
defaults write com.apple.desktopservices DSDontWriteNetworkStores true sudo find / -name ".DS_S ...
- 【心得】在脱离TFS的情况下,如何解除TFS绑定?
我们知道在有TFS的情况下,在文件-源代码管理-高级中可以解除TFS绑定. 但是如果我们出差去了,拿着笔记本电脑,打开解决方案的时候,会总是提示无法连接TFS,并且在源代码管理处尝试解除的时候也提示无 ...
- 1121高性能MySQL之运行机制
本文来自于拜读<高性能MySQL(第三版)>时的读书笔记作者:安明哲转载时请注明部分内容来自<高性能MySQL(第三版)> MySQL的逻辑构架 MySQL服务器逻辑架构 最上 ...
- 0929mysql前缀索引如何找到合适的位数
前缀索引,是指对于VARCHAR/TEXT/BLOB类型的字段建立索引时一般都会选择前N个字符作为索引.索引很长的字符列,会让索引变得大且慢.索引开始的部分字符,这样可以大大节约索引空间,从而提高索引 ...
- PHP与MySQL
这周学习了PHP与MySQL的搭接下面来给大家分享一下: 1.账号注册,论坛发帖... 思路:通过form表单提交到PHP页面,PHP页面往MySQL中插入数据: 2.账号登陆 思路:form提交数据 ...