zoukankan      html  css  js  c++  java
  • [暑假集训--数论]poj1595 Prime Cuts

    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

    问数字范围在 l 到 r 内的数中,大小排最中间的2k-1或者2k个是哪些

    暴力

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #define LL long long
     5 using namespace std;
     6 inline LL read()
     7 {
     8     LL x=0,f=1;char ch=getchar();
     9     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    10     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    11     return x*f;
    12 }
    13 int n,m;
    14 bool mk[100010];
    15 int p[100010],len;
    16 int rnk[100010];
    17 inline void getp()
    18 {
    19     p[++len]=1;rnk[1]=1;
    20     for (int i=2;i<=100000;i++)
    21     {
    22         if (!mk[i])
    23         {
    24             p[++len]=i;
    25             rnk[i]=len;
    26             for (int j=2*i;j<=100000;j+=i)mk[j]=1;
    27         }
    28     }
    29 }
    30 int main()
    31 {
    32     getp();
    33     while (~scanf("%d%d",&n,&m))
    34     {
    35         if (n<=0)continue;
    36         printf("%d %d:",n,m);
    37         while (mk[n])n--;
    38         int ls=rnk[n],l,r;
    39         if (ls&1)l=max(ls/2+1-m+1,1),r=min(ls/2+1+m-1,ls);
    40         else l=max(ls/2-m+1,1),r=min(ls/2+m,ls);
    41         for (int i=l;i<=r;i++)
    42         {
    43             printf(" %d",p[i]);
    44         }
    45         puts("
    ");
    46     }
    47 }
    poj 1595
  • 相关阅读:
    Xlua侧如何接受CSharp侧的可变参数
    C# 中如何精确地测量一段逻辑的执行时间
    C#中设计一个 ListPool 的方案
    unity中获取设备的信息
    Oracle-游标-取钱-存钱-转账
    Oracle 存储过程与java调用
    PL/SQL loop,while.for循环
    PL/SQL if case when
    PL/SQL %type %rowtype
    Oracle PLSQL入门
  • 原文地址:https://www.cnblogs.com/zhber/p/7285442.html
Copyright © 2011-2022 走看看