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

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【素数】【水题】的更多相关文章

  1. zzulioj--1775-- 和尚特烦恼1——是不是素数(素数水题)

    1775: 和尚特烦恼1--是不是素数 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 563  Solved: 193 SubmitStatusWeb ...

  2. hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题

    题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还 ...

  3. 蓝桥杯 算法训练 Torry的困惑(基本型)(水题,筛法求素数)

    算法训练 Torry的困惑(基本型) 时间限制:1.0s   内存限制:512.0MB      问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突 ...

  4. SPOJ CNTPRIME 13015 Counting Primes (水题,区间更新,求区间的素数个数)

    题目连接:http://www.spoj.com/problems/CNTPRIME/ #include <iostream> #include <stdio.h> #incl ...

  5. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  6. 2019浙大校赛--J--Extended Twin Composite Number(毒瘤水题)

    毒瘤出题人,坑了我们好久,从基本的素数筛选,到埃氏筛法,到随机数快速素数判定,到费马小定理,好好的水题做成了数论题. 结果答案是 2*n=n+3*n,特判1,2. 以下为毒瘤题目: 题目大意: 输入一 ...

  7. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  8. 一道cf水题再加两道紫薯题的感悟

    . 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. . 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整 ...

  9. HDU 2521 反素数 模拟题

    解题报告:水题,直接附上代码,只是觉得这题的作者是不是吃饱了饭撑的,反素数的概念跟这题一点关系都没有. #include<cstdio> int judge1(int k) { ; ;i& ...

  10. Goldbach`s Conjecture(素筛水题)题解

    Goldbach`s Conjecture Goldbach's conjecture is one of the oldest unsolved problems in number theory ...

随机推荐

  1. knockoutjs关键点

    <p>Your value: <input data-bind="value: someValue, valueUpdate: 'afterkeydown'"/& ...

  2. webservice调用接口,接口返回数组类型

    1. 其中sendSyncMsg1接口是方法名,Vector实现了List接口,xml是sendSyncMsg1的方法形参 Service service = new Service(); Call ...

  3. java_reflect_01

    最近学习java开始接触到了框架,突然觉得java反射很重要,因此在这里做了一些总结(参考园中大苞米大神的文章) 首先我们要认识一下Class: 一.Class类有什么用? class类的实例表示ja ...

  4. mysql的limit经典用法及优化

    用法一   SELECT `keyword_rank`.* FROM `keyword_rank` WHERE (advertiserid='59') LIMIT 2 OFFSET 1;   比如这个 ...

  5. Linux系统中,main函数的执行过程

    http://blog.csdn.net/rrerre/article/details/6728431

  6. Java学习----不变的常量

    byte: -128~+127 short int:129 long float:1.5f  (1.5被系统默认为double) double:4.5d char:'s'  '1' boolean:t ...

  7. java-base64

    1.encode public static String encode(byte[] bValue, String encode) { ByteArrayOutputStream o = new B ...

  8. thinkphp excel txt文件上传实现

    <?php/************************************************************************************** ***  ...

  9. php 数组 类对象 值传递 引用传递 区别

    一般的数据类型(int, float, bool)不做这方面的解说了 这里详细介绍一下数组和的类的对象作为参数进行值传递的区别 数组值传递 实例代码: <?php function main() ...

  10. c# 重新认识 Double 浮点型

    double test1 = 0; for (int i = 0; i < 100000000; i++) { test1 += 0.0001; } 请问 test1 的值是几? 答案是:999 ...