poj 1595 Prime Cuts
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10610 | Accepted: 4046 |
Description
Input
Output
Sample Input
21 2
18 2
18 18
100 7
Sample Output
21 2: 5 7 11 18 2: 3 5 7 11 18 18: 1 2 3 5 7 11 13 17 100 7: 13 17 19 23 29 31 37 41 43 47 53 59 61 67
Source
题意:给定你一个数n,让你求出1-n内有多少个素数,再给你一个数d,如果2*d大于素数的个数则全部输出;
否则,如果个数为单数,输出2*d - 1个并且以中间那个素数为中心分别向两边输出d-1个;
如果偶数个,输出2*d个,也是以中间那个素数为中心向两边扩展;————网上查的
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define max 1000
int prime[max+];
void get_prime(int n){
int i;
prime[]=;
prime[]=;
int index=;
for(i=;prime[index]<=n;i++){//得到第一个大于n的素数
int j=;//j不能==0!!
for(;j<=index&&prime[j]*prime[j]<=i;j++){
if(!(i%prime[j])){
break;
}
}
if(prime[j]*prime[j]>i){
prime[++index]=i;
}
}
//cout<<prime[index]<<endl;
}
int main()
{
get_prime(max);
int n,c;
while(cin>>n>>c){
int i=,j,s,e;
while(prime[i]<=n){
i++;
}
if(i%){
if(i<*c-){
s=;
e=i-;
}
else{
s=i/-(c-);
e=i/+(c-);
}
}
else{
if(i<*c){
s=;
e=i-;
}
else{
s=i/--(c-);
e=i/+(c-);
}
}
cout<<n<<" "<<c<<":";
for(j=s;j<=e;j++){
cout<<" "<<prime[j];
}
cout<<endl;
cout<<endl;//格式注意
}
return ;
}
poj 1595 Prime Cuts的更多相关文章
- POJ 1595 Prime Cuts (ZOJ 1312) 素数打表
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...
- ACM/ICPC 之 数论-素数筛选法 与 "打表"思路(POJ 1595)
何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据 ...
- poj 1595
#include <iostream> #define N 10010 using namespace std; int a[N],b[N]; int prime(int a) { int ...
- [暑假集训--数论]poj1595 Prime Cuts
A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In ...
- 双向广搜 POJ 3126 Prime Path
POJ 3126 Prime Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16204 Accepted ...
- poj 2689 Prime Distance(大区间素数)
题目链接:poj 2689 Prime Distance 题意: 给你一个很大的区间(区间差不超过100w),让你找出这个区间的相邻最大和最小的两对素数 题解: 正向去找这个区间的素数会超时,我们考虑 ...
- POJ 3126 Prime Path(素数路径)
POJ 3126 Prime Path(素数路径) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 The minister ...
- Miller_rabin算法+Pollard_rho算法 POJ 1811 Prime Test
POJ 1811 Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 32534 Accepted: 8 ...
- PoJ 1595 PrimeCuts
Prime Cuts Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9339 Accepted: 3562 Descri ...
随机推荐
- 相当郁闷的问题,TabHost选项卡标签图标始终不出现?
在学习Android TabHost布局过程中,很多教程告诉我,这样来显示选项卡标签的图标和文字: TapSpec spec1 = tabHost.newTabSpec("tab 1&quo ...
- Win RT Webview获取cookie
方法1: HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); var cookis = filter.CookieManager ...
- 二十三、MongoDb 数据库介绍、安装、启动和连接(非关系型数据库)
1.数据库和文件的主要区别 1. 数据库有数据库表.行和列的概念,让我们存储操作数据更方便2. 数据库提供了非常方便的接口,可以让 nodejs.php java .net 很方便的实现增加修改删除功 ...
- java数据库学习
//编写db类/* a加载驱动 驱动类要全路径 包名+类名 suround with try/catch * b设置参数url user pwd * c.连接数据库(import 'Connectio ...
- 15、xtrabackup 全量备份
xtrabackup 全量备份与恢复 安装 yum install https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2. ...
- “全栈2019”Java第六十三章:接口与抽象方法详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- “全栈2019”Java第四十八章:重写方法Override
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- TCP/IP学习笔记(2)-数据链路层
数据链路层有三个目的: 为IP模块发送和接收IP数据报. 为ARP模块发送ARP请求和接收ARP应答. 为RARP发送RARP请求和接收RARP应答 ip大家都听说过.至于ARP和RARP,ARP叫做 ...
- ACM-ICPC 2018青岛网络赛-H题 Traveling on the Axis
题目:略(不知道怎么从ZOJ搬题) 地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4054 把这题的每个点分成两种情况 ...
- word的xml文件中给文字添加超链
<w:hlink w:dest="http://xxx.com"><w:r></w:r></wr></w:hlink>& ...