Prime Cuts
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 11961   Accepted: 4553

Description

A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between (and including) 1 and N. Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.

Input

Each input set will be on a line by itself and will consist of 2 numbers. The first number (1 <= N <= 1000) is the maximum number in the complete list of prime numbers between 1 and N. The second number (1 <= C <= N) defines the C*2 prime numbers to be printed from the center of the list if the length of the list is even; or the (C*2)-1 numbers to be printed from the center of the list if the length of the list is odd.

Output

For each input set, you should print the number N beginning in column 1 followed by a space, then by the number C, then by a colon (:), and then by the center numbers from the list of prime numbers as defined above. If the size of the center list exceeds the limits of the list of prime numbers between 1 and N, the list of prime numbers between 1 and N (inclusive) should be printed. Each number from the center of the list should be preceded by exactly one blank. Each line of output should be followed by a blank line. Hence, your output should follow the exact format shown in the sample 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

[Submit]   [Go Back]   [Status]   [Discuss]

这个题很迷。。出错几乎都是格式错误。WA,PE了好多发。。

反正以后格式问题不乱搞就行了。

当做警戒

 #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<iostream>
#include <cmath>
#define ll long long
#define dscan(a) scanf("%d",&a)
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
#define MAXL 1105
#define maxn 1000005
int p[maxn],res,check[maxn];
int f[maxn][],cnt;
void getp()
{
mem(check,);
check[]=check[]=;
for (int i = ; i <=MAXL; ++i)
{
if (!check[i])
{
p[cnt++] = i;
}
for (int j = ; j < cnt; ++j)
{
if (i * p[j] > MAXL)
{
break;
}
check[i*p[j]] = ;
if (i % p[j] == )
{
break;
}
}
}
}
int main()
{
int n,c;
getp();
check[]=;
while(cin>>n>>c)
{
int sum=;
int pp[];
mem(pp,);
cout<<n<<" "<<c<<":";
for(int i=;i<=n;++i)
if(!check[i]) pp[++sum]=i;
//cout<<"sum="<<sum<<endl;
if((sum%&&sum<=*c-)||(sum%==&&sum<=*c))
{
for(int i=;i<=sum;++i) printf(" %d",pp[i]);
printf("\n\n");
}
else
{
if(sum%) {
int mid=(sum+)/;
for(int i=mid-(c-);i<=mid;++i) printf(" %d",pp[i]);
for(int i=mid+;i<=mid+(c-);i++) printf(" %d",pp[i]);
printf("\n\n");
}
else
{
for(int i=(sum-*c)/+;i<=(sum-*c)/+*c;++i) printf(" %d",pp[i]);
printf("\n\n");
}
}
}
return ;
}

POJ1595 Prime Cuts的更多相关文章

  1. [暑假集训--数论]poj1595 Prime Cuts

    A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In ...

  2. poj 1595 Prime Cuts

    Prime Cuts Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10610   Accepted: 4046 Descr ...

  3. HDOJ 1319 Prime Cuts<数论>

    学会了不难.通过这道题学习了两点: 1:筛选法求素数. 2:在写比较长的程序的时候,给每个功能部分加上注释,思路会更清晰. 题意: 1.题目中所说的素数并不是真正的素数,包括1: 2.需要读懂题意,对 ...

  4. POJ 1595 Prime Cuts (ZOJ 1312) 素数打表

    ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...

  5. POJ1595_Prime Cuts【素数】【水题】

    Prime Cuts Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 10464Accepted: 3994 Description ...

  6. acm数学(转)

    这个东西先放在这吧.做过的以后会用#号标示出来 1.burnside定理,polya计数法    这个大家可以看brudildi的<组合数学>,那本书的这一章写的很详细也很容易理解.最好能 ...

  7. ACM/ICPC 之 数论-素数筛选法 与 "打表"思路(POJ 1595)

    何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据 ...

  8. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  9. [转] POJ数学问题

    转自:http://blog.sina.com.cn/s/blog_6635898a0100magq.html 1.burnside定理,polya计数法 这个大家可以看brudildi的<组合 ...

随机推荐

  1. 当GetWindowText获取不到标题时可以用SendMessage

    GetWindowText所有父窗口标题基本可以获取到, 但是当获取父窗口下的子窗口控件标题文本时有时候就没那么好用了, 这个时候可以通过SendMessage发送消息来获取,也很简单,C/C++代码 ...

  2. 【前端_js】理解 JavaScript 的 async/await

    async 和 await 在干什么 任意一个名称都是有意义的,先从字面意思来理解.async 是“异步”的简写,而 await 可以认为是 async wait 的简写.所以应该很好理解 async ...

  3. 第六篇:python中numpy.zeros(np.zeros)的使用方法

    用法:zeros(shape, dtype=float, order='C') 返回:返回来一个给定形状和类型的用0填充的数组: 参数:shape:形状 dtype:数据类型,可选参数,默认numpy ...

  4. Nuxt.js 基础入门教程

    原文链接 Vue 开发一个单页面应用,相信很多前端工程师都已经学会了,但是单页面应用有一个致命的缺点,就是 SEO 极不友好.除非,vue 能在服务端渲染(ssr)并直接返回已经渲染好的页面,而并非只 ...

  5. Python知识点入门笔记——特色数据类型(列表)

    Python中提供了列表这种数据类型(类型为list)来存储多个值构成的序列 用逗号将不同数据分隔开,整体放在一个方括号[]里就创建了列表 列表中的数据类型可以是相同的,也可以是不同的 列表中还可以嵌 ...

  6. JQ剪辑图片插件,适用于移动端和PC端

    主要用到以下JS文件: <script src="js/photo/iscroll-zoom.js"></script> <script src=&q ...

  7. hdu5319 简单模拟

    题意很好懂,大致就是三种颜色,红和蓝一起会变绿,给个终态矩阵,问从原始状态到终态最少画几笔?  按一定规则画 思路就是记红为1,蓝为2,绿为3,先遍历绿色,针对每一块绿色进行删除,每找到一块绿色,首先 ...

  8. HttpRunnerManager 接口自动化测试平台 搭建实践

    一.需要准备的知识点 1. linux: 安装 python3.nginx 安装和配置.mysql 安装和配置 2. python: django 配置.uwsgi 配置 二.我搭建的环境 1. Ce ...

  9. StartWith 测试

    var clientConfiguration = GetConfiguration("couchbase.json"); ClusterHelper.Initialize(cli ...

  10. OpenStack之虚机热迁移代码解析

    OpenStack之虚机热迁移代码解析 话说虚机迁移分为冷迁移以及热迁移,所谓热迁移用度娘的话说即是:热迁移(Live Migration,又叫动态迁移.实时迁移),即虚机保存/恢复(Save/Res ...