• [暑假集训--数论]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
  • 相关阅读:
    ApacheShiro反序列化远程代码执行 漏洞处理
    js判断是电脑(pc)访问还是手机(mobile)访问
    MySQL实现主从库,AB复制配置
    js实现回到顶部功能
    JAVA结合Redis处理缓存穿透问题
    Apache Shiro使用官方自带的生成AES密钥
    JAVA将Object数组转换为String数组
    JAVA中数组(Array)、字符串(String)、集合(List、Set)相互转换
    输入npm install 报错npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.13.1 postinstall: `node scripts/build.js`
    tomcat的部署jspgou+优化
  • 原文地址:https://www.cnblogs.com/zhber/p/7285442.html
Copyright © 2020-2023  润新知