zoukankan      html  css  js  c++  java
  • ural 1086. Cryptography

    1086. Cryptography

    Time limit: 2.0 second
    Memory limit: 64 MB
    While preparing this problem set the jury has run into the following problem: it was necessary to send by e-mail the texts of the problems. As it is well known, e-mail is not reliable, messages are sent not enciphered, there is a danger that someone can intercept them. The members of the program committee wanted no participant know the texts of the problems before the start of the contest. That's why they resorted to cryptography methods in order to save the texts of the problems from an unsanctioned reading. The jury gas worked up a new way of enciphering of a text. It is not patented yet, so it's kept secret. However, we'll reveal you one secret: the new algorithm is based on the work with prime numbers. In particular, in uses a calculation of n-th by order prime number.
    Several members of the program committee independently have worked up programs that make such calculations, but these programs produce different answers. Each one of the programmers is sure that his program works correctly. That's why the jury has reached the deadlock and can't continue working. The contest is about not to take place.
    You are to help to the jury and to save the contest. We want you to write a program that calculates the n-th by order prime number. The main thing is that your program should work correctly.

    Input

    First line contains a positive integer k. Then k positive integers follow (one in each line). The numbers don't exceed 15000.

    Output

    For each number n you should output the n-th by order prime number. Each number should be in its line.

    Sample

    inputoutput
    4
    3
    2
    5
    7
    
    5
    3
    11
    17

    题意:求第i个素数,样例解释:第一行一个T,表示要输出T个素数,接下来的T行每行有一个整数 n 表示要求输出第n个素数

    思路:我是先将15000个素数全部算出来,采用传统的方法肯定是不行的,利用定理:一个素数的倍数一定不是素数进行计算

    AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<string>
     7 
     8 
     9 using namespace std;
    10 
    11 bool kiss[164000];
    12 int numbers[15100]={0};
    13 int sgin=1;
    14 
    15 
    16 int main()
    17 {
    18     memset(kiss,true,sizeof(kiss));
    19     for(int i=2;i<=164000;i++){//统计出15000个素数
    20         if(kiss[i]){
    21             numbers[sgin++]=i;
    22             for(int k=1;i*k<=164000;k++){
    23                 kiss[i*k]=false;
    24             }
    25         }
    26     }
    27     int T;
    28     scanf("%d",&T);
    29     while(T){//按照要求去输出
    30         int n;
    31         scanf("%d",&n);
    32         printf("%d
    ",numbers[n]);
    33         T--;
    34     }
    35     return 0;
    36 }
    View Code
  • 相关阅读:
    数30的小程序
    convert curl command into java HttpGet
    优秀技术文章转载备份 --- 变速原理
    用 c 调用 win-api 实现自动点击c# winform 程序 的按钮
    win 10 安装 glew 方法
    《想到什么更新什么系列》processing 性能优化
    processing 根据物体移动方向改变朝向
    openFrameworks 无法生成exe已经找不到dll的解决方案
    UE4 无法打开源文件“file_name.generated.h”(Cannot open source file name.generated.h)
    UE4 重新编译老版本的插件
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3403724.html
Copyright © 2011-2022 走看看