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 ...
随机推荐
- 个人Blog小程序开发完毕
今天忙了一天,算是把这个小程序弄好了,包括小程序前端页面.接口对接.后台系统.服务器架 设.域名备案.证书安装(现在阿里云的免费证书怎么审核要这么久啊,到现在还在审核中) 先上截图: 这个背景图片的替 ...
- Java堆空间溢出解决方法 Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
一般通过java -jar filename.jar运行jar包,但是当运行的java程序需要较大的内存时,可能会造成堆空间溢出. 例如,加载了几个G大小的json文件,运行报错: Exception ...
- IOS开发使用GCD后台运行
什么是GCD Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法.该方法在Mac OS X 10.6雪豹中首次推出,并随后被引入到了iOS4.0中.GCD ...
- python3 使用matplotlib画图问题
保存图片的问题 在画子图并保存图片的时候,用如下代码保存的图片总是不能显示,但是在运行的过程中能够正常显示图片. # coding:utf-8 from pylab import * # 创建子图 f ...
- HDU - 4336:Card Collector(min-max容斥求期望)
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...
- maven报错【Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of】
[自己的操作] (1)windows -> Preferences -> maven 的settings.xml文件中.m2的位置已经失效,更改正确后尝试 (2)pom.xml还有下面错误 ...
- Python学习-类
类是对象的模板或蓝图,类是对象的抽象化,对象是类的实例化 在python中,一个对象的特征也称为属性(attribute),它所具有的的行为也称为方法(method) 对象 = 属性(特征)+方法(行 ...
- asciidoctor 安装试用
备注: asciidoctor 是asciidoc 的增强,使用简单,模板比较丰富,对于持续集成方面的开发也是一个不错的工具 1. 安装 a. 环境准备 MRI Ruby 1.8.7, 1. ...
- python socket的应用 以及tcp中的粘包现象
1,socket套接字 一个接口模块,在tcp/udp协议之间的传输接口,将其影藏在socket之后,用户看到的是socket让其看到的. 在tcp中当做server和client的主要模块运用 #s ...
- Oracle修改字段值包含&字符
昨天在更新一个表的字段时发现pl/sql弹出变量框,它认为我要改的字段值中包含未定义的变量.比如我执行一个脚本: update t_wlf_config set configvalue = 'hell ...