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中的图片处理
大图片处理 大图片处理是将原来像素高的转换为像素低的图片,比如原来图片是1024*768的,而手机屏幕是800*600的,这时候就需要进行转换.转换的方式很简单就是等比例缩放. package xid ...
- java中的重绘
void java.awt.Container.validate()Validates this container and all of its subcomponents.这个函数更新容器及其全部 ...
- Linux下安装libiconv使php支持iconv函数
libiconv组件安装好了可以让我们php支持iconv函数了,这个函数的作用就是字符编码强制转换了,下面和111cn小编一起来看一个Linux中安装libiconv使php支持iconv函数的例子 ...
- [转]跟我一起学extjs5(02--建立工程项目)
原文地址:http://blog.csdn.net/jfok/article/details/35569057 目录(?)[+] 跟我一起学extjs5(02--建立工程项目) 我们先建立一个java ...
- 【CodeVS 1198】【NOIP 2012】国王游戏
http://codevs.cn/problem/1198/ 推导一翻,排好序后,直接上高精度. #include<cstdio> #include<cstring> #inc ...
- git之旅【第二篇】
1,git的安装 最早Git是在Linux上开发的,很长一段时间内,Git也只能在Linux和Unix系统上跑.不过,慢慢地有人把它移植到了Windows上.现在,Git可以在Linux.Unix.M ...
- Notes on 'Efficient Graph-Based Image Segmentation'
Notes on Efficient Graph-Based Image Segmentation 算法的目标 按照一种确定的标准, 将图片分割成细粒度的语义区域, 即Super pixel. 算法步 ...
- C# 通过后台获取浏览器域名
通过httpContext.获取当前地址当前主机域名 string url = HttpContext.Current.Request.Url.Host.ToString();
- 【POJ 1789】Truck History(最小生成树)
题意:距离定义为两个字符串的不同字符的位置个数.然后求出最小生成树. #include <algorithm> #include <cstdio> #include <c ...
- tableView异步下载图片/SDWebImage图片缓存原理
问题说明:假设tableView的每个cell上的imageView的image都是从网络上获取的数据.如何解决图片延迟加载(显示很慢).程序卡顿.图片错误显示.图片跳动的问题. 需要解决的问题: 1 ...