[UVa1210]Sum of Consecutive Prime Numbers(前缀和,打表)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3651
题意:问一个数n能拆成多少种连续的素数和。
筛出所有素数发现只有1200个,维护素数的前缀和,再打出所有区间的前缀和的表,统计出来,直接查询。
#include <bits/stdc++.h>
using namespace std; const int maxn = ;
bool isprime[maxn];
int prime[maxn];
int sum[maxn];
int pcnt;
int n;
int mp[];
void init() {
memset(isprime, true, sizeof(isprime));
memset(prime, , sizeof(prime));
pcnt = ;
}
void getPrime() {
init();
prime[] = prime[] = ;
for(int i = ; i <= maxn; i++) {
if(isprime[i]) prime[++pcnt] = i;
for(int j = ; j <= pcnt; j++) {
if(i * prime[j] > maxn) break;
isprime[i*prime[j]] = ;
if(i % prime[j] == ) break;
}
}
} int main() {
// freopen("in", "r", stdin);
// freopen("out", "w", stdout);
getPrime();
memset(sum, , sizeof(sum));
sum[] = prime[];
for(int i = ; i < pcnt; i++) sum[i] = sum[i-] + prime[i];
memset(mp, , sizeof(mp));
for(int i = ; i < pcnt; i++) {
for(int j = i; j < pcnt; j++) {
mp[sum[j]-sum[i]]++;
}
}
while(~scanf("%d", &n) && n) {
printf("%d\n", mp[n]);
}
return ;
}
[UVa1210]Sum of Consecutive Prime Numbers(前缀和,打表)的更多相关文章
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- 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 Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- POJ2739 Sum of Consecutive Prime Numbers(尺取法)
POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...
- POJ2739 Sum of Consecutive Prime Numbers 2017-05-31 09:33 47人阅读 评论(0) 收藏
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25225 ...
- Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS Memory Limit: 6 ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
随机推荐
- jboss-as 目录结构(转)
jboss-as 目录结构(Directory Structure) Directory Description bin Contains startup, shutdown and other sy ...
- 继承(引用~析构~virtual)
[1]程序1 #include <iostream> using namespace std; class Base { private: int m_nBase; public: Bas ...
- android 项目学习随笔五(JSON解析)
1.利用Xutils获取网络数据 /** * 从服务器获取数据 需要权限: <uses-permission * android:name="android.permission.IN ...
- linux主机vps简单性能测试
第一,CPU.内存.硬盘检测 cat /proc/cpuinfo (查看CPU信息) cat /proc/meminfo (查看内存信息) df -lh (查看硬盘信息) 这个命令可以看到我们购买的V ...
- java中length,length(),size()的区别
1. java中的length属性是针对数组说的,比如说你声明了一个数组,想知道这个数组的长度则用到了length这个属性.2. java中的length()方法是针对字符串String说的,如果想看 ...
- 精简高效的CSS命名准则/方法
/* ---------------------single CSS----------------------- */ /* display */ .dn{display:none;} .di{di ...
- javaWeb request乱码处理
//解决get方式提交的乱码 String name = request.getParameter("name"); name=new String(u ...
- BlueDroid介绍 【转】
转自:http://blog.csdn.net/fen_liu/article/details/41213167 [-] 基本结构 代码区 http://www.cnblogs.com/hzl6255 ...
- ARM、Intel、MIPS处理器啥区别?看完全懂了【转】
转自:http://news.mydrivers.com/1/472/472317.htm 安卓支持三类处理器(CPU):ARM.Intel和MIPS.ARM无疑被使用得最为广泛.Intel因为普及于 ...
- webservice cxf error:java.lang.IllegalArgumentException: Argument(s) "type" can't be null.
客户端请求DTO和服务器端的DTO定义不一样,客户端必须定义@XmlAccessorType和@XmlType,如: @XmlAccessorType(XmlAccessType.FIELD) @Xm ...