题目链接

题意:输入一个数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(素数打表 + 连续和)的更多相关文章

  1. POJ 2739 Sum of Consecutive Prime Numbers(素数)

    POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...

  2. poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697 ...

  3. CodeForces 385C Bear and Prime Numbers 素数打表

    第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...

  4. UVA 10539 - Almost Prime Numbers 素数打表

    Almost prime numbers are the non-prime numbers which are divisible by only a single prime number.In ...

  5. Sum of Consecutive Prime Numbers(素数打表+尺取)

    Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...

  6. POJ 2739 Sum of Consecutive Prime Numbers【素数打表】

    解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memo ...

  7. POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19895 ...

  8. POJ2739_Sum of Consecutive Prime Numbers【筛法求素数】【枚举】

    Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19350 Ac ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. Orchard创建全局应用

    Orchard的本地化管理托管于一个外部服务(Crowdin),这个项目是公开的且欢迎大家做贡献. Orchard支持两种类型的本地: Orchard应用程序以及已安装模块中的文本字符串的本地化(其实 ...

  2. 20151023 - discuz 6 中 insenz 营销推广失效的问题

    将很久之前的论坛重新放在网络上,发现首页打开非常慢,用 Web Inspector 检查,发现 insenz.com 已失效导致. 解决办法: 1.进入数据库:执行 SELECT * FROM cdb ...

  3. C#:异步编程和线程的使用(.NET 4.5 )

    摘自:http://www.codeproject.com/Articles/996857/Asynchronous-programming-and-Threading-in-Csharp-N(葡萄城 ...

  4. EF增删改查操作

    增 using (StudentEntities ent = new StudentEntities()) { User aNewUser = new User() { Age = , Name = ...

  5. 【对noip结束后一个月内的总结】

    最近在刷一些树结构,但发现没有一个提纲,觉得有点不知所措,经常学完一个就发现还有比它更好的,而且比较耗时间.于是沙茶准备按顺序刷bzoj的省选题,看看效果怎么样……求大神指教

  6. IIS7.5开启GZip压缩

    在IIS7.5选择要开启GZip压缩的网站,在功能视图中找到并双击"压缩"图标,在压缩界面中钩选"启用静态内容压缩"和"启用动态内容压缩", ...

  7. Linux下sysstat工具学习

    Linux下,我们多用ssh链接服务器远程操控.对于系统的监控必不可少,sysstat很不错的监控工具包. sysstat官网:http://sebastien.godard.pagesperso-o ...

  8. MAC中查看Python安装路径

    [admin@admindeMac:~]which  Python /usr/bin/Python

  9. redis的主从复制配置

    redis的主从复制配置 一.     原理 Redis的主从复制功能非常强大,一个master可以拥有多个slave,而一个slave又可以拥有多个slave,如此下去,形成了强大的多级服务器集群架 ...

  10. C#中的Where和Lambda表达式

    1 2 3 4 5 6 7 8 9 10 11 List<string> listString = new List<string>(); listString.Add(&qu ...