zoukankan      html  css  js  c++  java
  • ural1086. 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
    

    Notes

    The prime number is a positive integer that has exactly two different positive divisors, i.e. 1 is not a prime number.

    Problem Author: folklore
    Problem Source: The 3rd high school children programming contest, USU, Yekaterinburg, Russia, March 4, 2001

    思路:水题, 打个素数表就可以

     1 #include <iostream>
     2 #include <sstream>
     3 #include <fstream>
     4 #include <string>
     5 #include <vector>
     6 #include <deque>
     7 #include <queue>
     8 #include <stack>
     9 #include <set>
    10 #include <map>
    11 #include <algorithm>
    12 #include <functional>
    13 #include <utility>
    14 #include <bitset>
    15 #include <cmath>
    16 #include <cstdlib>
    17 #include <ctime>
    18 #include <cstdio>
    19 #include <string>
    20 using namespace std;
    21 int N, T;
    22 const int M = 1e6+5;
    23 bool a[M];
    24 int prime[M];
    25 int cnt = 0;
    26 void init() {
    27     for(int i = 2; i < M; i++) a[i] = true;
    28     for(int i = 2; i < M; i++) {
    29         if(a[i]) {
    30             cnt++;
    31             prime[cnt] = i;
    32         }
    33         for(int j = 1; j <= cnt; j++) {
    34             if(i * prime[j] >= M) break;
    35             a[i*prime[j]] = false;
    36             if(i % prime[j] == 0) break;
    37         }
    38     }
    39 }
    40 int main() {
    41     //freopen("in.txt", "r", stdin);
    42     init();
    43     int n, m;
    44     scanf("%d", &n);
    45     while(n--){
    46         scanf("%d", &m);
    47         printf("%d
    ", prime[m]);
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    CF932E Team Work(第二类斯特林数)
    BZOJ 3732: Network(Kruskal重构树)
    BZOJ 2753: [SCOI2012]滑雪与时间胶囊(最小生成树)
    BZOJ 2286: [Sdoi2011]消耗战(虚树+树形dp)
    hdu 4336 Card Collector(状压dp/Min-Max反演)
    BZOJ 3622: 已经没有什么好害怕的了(二项式反演)
    BZOJ 2839: 集合计数(二项式反演)
    CF gym 101933 K. King's Colors(二项式反演)
    BZOJ 1101: [POI2007]Zap(莫比乌斯反演)
    BZOJ 3747: [POI2015]Kinoman(线段树)
  • 原文地址:https://www.cnblogs.com/cshg/p/5892495.html
Copyright © 2011-2022 走看看