PoJ 1595 PrimeCuts
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 9339 | Accepted: 3562 |
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
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 1200
bool hash[maxn];
void inithash()
{
int i,j;
for(j=; j<maxn; j+=)
hash[j]=;
for(i=; i<; i+=)
if(!hash[i])
for(j=i*i; j<maxn; j+=i)
hash[j]=;
}
int primenum(int N)
{
int num=;
for(int i=; i<=N; i++)
if(!hash[i])
num++;
return num;
}
int main()
{
inithash();
int N,len,num,tmp;
while(scanf("%d%d",&N,&len)!=EOF)
{
printf("%d %d:",N,len);
num=primenum(N);
if(num%==)
{
if(num-(*len)<=)
{
for(int i=; i<=N; i++)
if(!hash[i])
{
printf(" %d",i);
}
printf("\n\n");
}
else
{
tmp=;
for(int i=; i<=N; i++)
if(!hash[i])
{
if(tmp>=(num-(*len))/&&tmp<*len+(num-(*len))/)
printf(" %d",i);
tmp++;
}
printf("\n\n");
}
}
else
{
if(num-(*len-)<=)
{
for(int i=; i<=N; i++)
if(!hash[i])
{
printf(" %d",i);
}
printf("\n\n");
}
else
{
tmp=;
for(int i=; i<=N; i++)
if(!hash[i])
{
if(tmp>=(num-(*len-))/&&tmp<*len-+(num-(*len-))/)
printf(" %d",i);
tmp++;
}
printf("\n\n");
}
}
}
return ;
}
PoJ 1595 PrimeCuts的更多相关文章
- ACM/ICPC 之 数论-素数筛选法 与 "打表"思路(POJ 1595)
何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据 ...
- poj 1595
#include <iostream> #define N 10010 using namespace std; int a[N],b[N]; int prime(int a) { int ...
- POJ 1595 Prime Cuts (ZOJ 1312) 素数打表
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...
- POJ 1595 素数打表水题
[题意简述]:给出N和C,让我们求出N以内的包含N的素数,然后依据若N以内的素数为奇数个,就将中间2*c-1个素数输出:若为偶数个.就将中间2*c个素数输出. [分析]:仅仅要题意理解就简单了. 详见 ...
- poj 1595 Prime Cuts
Prime Cuts Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10610 Accepted: 4046 Descr ...
- [暑假集训--数论]poj1595 Prime Cuts
A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
随机推荐
- SDKMAN 软件开发工具包管理器
SDKMAN 是用来在类Unix 系统中管理多个版本的开发环境的工具.提供命令行接口来安装.切换.删除.列出候选版本. SDKMAN!是在大多数基于Unix的系统上管理多个软件开发套件的并行版本的工具 ...
- img 在chrome和Firefox下的兼容性
Firefox 5.下:没有重叠在一起: chrome 下: 两个重叠在一起, 原因: img标签,在两个浏览器下展示效果不一样, 解决办法:指明展示:
- sssp-springmvc+spring+spring-data-jpa问题总结
问题:Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to re ...
- linux发行版本centos7.4上安装jdk,tomcat,mariadb良心教程
准备工作: 本地安装:rpm -ivh 程序名 因为jdk,tomcat,mysql的安装过程需要从网上下载部分支持包才可以继续,所以要求提前安装下载好依赖. yum install glibc.i6 ...
- POJ1733 Parity game 【扩展域并查集】*
POJ1733 Parity game Description Now and then you play the following game with your friend. Your frie ...
- 前端(四):JavaScript面向对象之自定义对象
一.对象 1.字面量创建对象 var person = { name: "sun", age: 18, work: function () { console.log(this.n ...
- Vue生命周期函数详解
vue实例的生命周期 1 什么是生命周期(每个实例的一辈子) 概念:每一个Vue实例创建.运行.销毁的过程,就是生命周期:在实例的生命周期中,总是伴随着各种事件,这些事件就是生命周期函数: 生命周期: ...
- tomcat nginx 证书切换
1. 导出公钥 keytool -export -alias tomcat -keystore <you jks>wsriakey.keystore -file <outputfil ...
- 基于jquery 的ajax 文件下载
ajax 文件下载,实际上就是模拟表单提交,代码如下: function download(url, data, method){ //url and data options required if ...
- L2TP/IPSec一键安装脚本
本脚本适用环境:系统支持:CentOS6+,Debian7+,Ubuntu12+内存要求:≥128M更新日期:2017 年 05 月 28 日 关于本脚本:名词解释如下L2TP(Layer 2 Tun ...