POJ1595_Prime Cuts【素数】【水题】
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
题目大意:给你两个数N和C,算出1~N(包含N)之间的素数序列,
若素数个数为奇数,则输出素数序列中心的2*C-1个素数。
若素数个数为偶数。则输出素数序列中心的2*C个素数。
输出个数中说若C>素数个数。则输出整个素数序列。
思路:筛法求素数打表,之后求出素数序列的中心位置。推断奇偶并输出
注意:此题中。1被当做了质数(仅仅限本题),数据规模开成1000是不够
的。须要开成1100。应该是測试数据超范围了。
#include<stdio.h> int Prime[1100],PrimeNum[1100]; int IsPrime()
{
for(int i = 1; i <= 1100; i++)
Prime[i] = 1;
for(int i = 2; i <= 1100; i++)
{
for(int j = i+i; j <= 1100; j+=i)
Prime[j] = 0;
}
int num = 1;
for(int i = 0; i <= 1100; i++)
if(Prime[i])
PrimeNum[num++] = i;
return num;
}
int main()
{
int num = IsPrime();
int N,C,pos;
while(~scanf("%d%d",&N,&C))
{
pos = 0;
for(int i = 1; i < num; i++)
{
if(N >= PrimeNum[i] && N < PrimeNum[i+1])
{
pos = i;
break;
}
}
printf("%d %d:",N,C);
if(C > pos && pos%2==0)
C = pos/2;
else if(C > pos)
C = (pos+1)/2;
if(pos%2 == 1)
{
for(int i = (pos-(C*2-1))/2+1; i <= (pos-(C*2-1))/2+C*2-1; i++)
printf(" %d",PrimeNum[i]);
printf("\n\n");
}
else
{
for(int i = (pos-C*2)/2+1; i <= (pos-C*2)/2+C*2; i++)
printf(" %d",PrimeNum[i]);
printf("\n\n");
} }
return 0;
}
POJ1595_Prime Cuts【素数】【水题】的更多相关文章
- zzulioj--1775-- 和尚特烦恼1——是不是素数(素数水题)
1775: 和尚特烦恼1--是不是素数 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 563 Solved: 193 SubmitStatusWeb ...
- hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题
题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还 ...
- 蓝桥杯 算法训练 Torry的困惑(基本型)(水题,筛法求素数)
算法训练 Torry的困惑(基本型) 时间限制:1.0s 内存限制:512.0MB 问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突 ...
- SPOJ CNTPRIME 13015 Counting Primes (水题,区间更新,求区间的素数个数)
题目连接:http://www.spoj.com/problems/CNTPRIME/ #include <iostream> #include <stdio.h> #incl ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 2019浙大校赛--J--Extended Twin Composite Number(毒瘤水题)
毒瘤出题人,坑了我们好久,从基本的素数筛选,到埃氏筛法,到随机数快速素数判定,到费马小定理,好好的水题做成了数论题. 结果答案是 2*n=n+3*n,特判1,2. 以下为毒瘤题目: 题目大意: 输入一 ...
- POJ 水题(刷题)进阶
转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...
- 一道cf水题再加两道紫薯题的感悟
. 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. . 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整 ...
- HDU 2521 反素数 模拟题
解题报告:水题,直接附上代码,只是觉得这题的作者是不是吃饱了饭撑的,反素数的概念跟这题一点关系都没有. #include<cstdio> int judge1(int k) { ; ;i& ...
- Goldbach`s Conjecture(素筛水题)题解
Goldbach`s Conjecture Goldbach's conjecture is one of the oldest unsolved problems in number theory ...
随机推荐
- LINUX系统安装MYSQL命令,纯手打
1.下载安装包 wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz 2. ...
- 12 Integer to Roman(int转罗马数字Medium)
题目意思:1-3999转罗马数字 思路:从大往小减 ps:这题有点蛋疼 class Solution { public: string intToRoman(int num) { string a[] ...
- text-overflow:ellipsis 的应用(转载)
关键字: text-overflow:ellipsis 语法:text-overflow : clip | ellipsis 取值: clip :默认值 .不显示省略标记(...),而是简单的裁切. ...
- windows8.1 下搭建配置apache+php+mysql
软件版本: apache:Apache 2.4.10 Win64 http://www.apachelounge.com/download/VC11/binaries/httpd-2.4.10- ...
- ZOJ1074 (最大和子矩阵 DP)
F - 最大子矩阵和 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Descri ...
- Razor 语法
Razor 语法 原文:Razor Syntax Reference作者:Taylor Mullen.Rick Anderson翻译:刘怡(AlexLEWIS)校对:何镇汐 什么是 Razor? ...
- 用C#实现网络爬虫(一)
网络爬虫在信息检索与处理中有很大的作用,是收集网络信息的重要工具. 接下来就介绍一下爬虫的简单实现. 爬虫的工作流程如下 爬虫自指定的URL地址开始下载网络资源,直到该地址和所有子地址的指定资源都下载 ...
- ISO14443协议中,卡片对RATS,PPS,IBLOCK的处理约定
这几天总是看到有人因为这几条规则没处理好,结果检测时通不过,其实看看最新版的ISO14443协议就明白了. 协议中明确要求几条: 1.在激活状态后,如果收到一个无错的RATS命令后,卡片返回atr,此 ...
- [Delphi]检查URL是否有效的函数
function CheckUrl(url: string): boolean; var hSession, hfile, hRequest: hInternet; dwindex, dwcodele ...
- Javascript的IE和Firefox兼容性汇编
以下以 IE 代替 Internet Explorer,以 MF 代替 Mozzila Firefox 1. document.form.item 问题 (1)现有问题: 现有代码 ...