题目链接

题意:输入一个数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. C# WinForm捕获全局异常

    网上找的C# WinForm全局异常捕获方法,代码如下: static class Program { /// <summary> /// 应用程序的主入口点. /// </summ ...

  2. scrollHeight,scrollLeft,offsetHeight,offsetLeft

    scrollHeight:内部元素的绝对高度,包含内部元素的隐藏的部分scrollWidth:内部元素的绝对宽度,包含内部元素的隐藏的部分 scrollLeft:设置或获取位于对象左边界和窗口中目前可 ...

  3. 【JavaScript】 闭包 我战战兢兢的接触了它

    源:http://www.liaoxuefeng.com 1. 注意这里用了一个“创建一个匿名函数并立刻执行”的语法: (function (x) { return x * x; })(3); 理论上 ...

  4. 对Ip地址进行验证

    依据正则表达式 boolean voliate(String ipString) {        // 匹配ip正则表达式        String ip = "([1-9]|[1-9] ...

  5. android 入门笔迹(1)

    环境搭建JDK,JRE,Android SDK,ADT,Eclipse,安卓模拟器AVD xml控制UI界面  Java代码控制UI界面  XML与Java混合控制UI界面  UI:userinter ...

  6. spring 集成shiro 之 自定义过滤器

    在web.xml中加入 <!-- 过期时间配置 --> <session-config><session-timeout>3</session-timeout ...

  7. iOS开发小技巧--根据文字,计算label中文字高度

  8. ES6新特性:Function函数扩展, 扩展到看不懂

    本文所有Demo的运行环境为nodeJS, 参考:让nodeJS支持ES6的词法----babel的安装和使用 : 函数的默认值: 如果有参数 ,那就用参数, 如果没有参数, 那就用默认的参数: aj ...

  9. 让Windows新建UTF-8编码的文本文件

    一直以来都是使用[右键->新建->文本文件]的方法来新建一个代码文件,但是存在一个问题新建的文件是大小为0字节的.对于大小为0字节的文件文件,文本编辑器一般都使用MBCS编码,而MBCS编 ...

  10. java判断request请求是手机还是pc终端

    /** * 判断请求是否手机端 * @param req * @return */ public static boolean isMobile(HttpServletRequest req) { U ...