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

input output
4
3
2
5
7
5
3
11
17

Hint

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

算法:

构建素数表,假设已经构建了素数表[p1,p2,p3……pk],找出第k+1个素数,依次将待检测的奇数n 除以pi(1 <= i <= k),若整除,则说明n为合数,否则为素数,继续构建素数表,直至素数表中的数目达到要求
// Ural Problem 1086. Cryptography
// Judgement result: Accepted
// Submission Date: 10:51 16 Jan 2014
// Run Time: 0.812s
// Memory used: 273KB
// Language: GCC 4.7.2 C11
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/// [解题方法]
// 简单素数题,直接打表判断 #include<stdio.h> int a[];
void init()
{
int i, count, flag, j;
flag = ;
count = ;
a[] = ;
a[] = ;
j = ;
while() {
for(i = ; i <= count; i++){
if(j % a[i] == ) {
flag = ;
break;
}
}
if(flag){
count++;
a[count] = j;
}
flag = ;
j += ;
if(count > ) break;
}
} void solve()
{
int n, N;
init();
scanf("%d", &N);
while(N--) {
scanf("%d", &n);
printf("%d\n", a[n]);
}
} int main()
{
solve();
return ;
}

Ural 1086 - Cryptography的更多相关文章

  1. URAL题解二

    URAL题解二 URAL 1082 题目描述:输出程序的输入数据,使得程序输出"Beutiful Vasilisa" solution 一开始只看程序的核心部分,发现是求快排的比较 ...

  2. 【线性筛】【筛法求素数】【素数判定】URAL - 2102 - Michael and Cryptography

    暴力搞肯定不行,因此我们从小到大枚举素数,用n去试除,每次除尽,如果已经超过20,肯定是no.如果当前枚举到的素数的(20-已经找到的质因子个数)次方>剩下的n,肯定也是no.再加一个关键的优化 ...

  3. .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数

    .Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...

  4. ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学

    ECC ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学,是目前已知的公钥体制中,对每比特所提供加密强度最高的一种体制.在软件注册保护方面起到很大的作用,一般的序列 ...

  5. "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法

    .net web程序使用rsa算法进行加解密时,程序报告“System.Security.Cryptography.CryptographicException: 拒绝访问”错.按网上搜的解决方法做了 ...

  6. BZOJ 1086: [SCOI2005]王室联邦

    1086: [SCOI2005]王室联邦 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1399  Solved: ...

  7. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  8. System.Security.Cryptography.CryptographicException: 指定了无效的提供程序类型

    这两天在调用银联在线的支付接口,把银联提供的demo代码copy过来放到自己网站上,生成通过了,但是运行的时候就报错了: 指定了无效的提供程序类型. 说明: 执行当前 Web 请求期间,出现未经处理的 ...

  9. [POJ2109]Power of Cryptography

    [POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...

随机推荐

  1. 转:说说angularjs中的$parse和$eval

    说说AngularJS中的$parse和$eval AngularJS的初学者常常会对$parse和$eval两个内建服务感到有些困惑,今天我们就来说说AngularJS中的$parse和$eval. ...

  2. 在原有3306端口mysqld服务的情况再搭建第二个3308端口的mysql实例

    1 download the tar.gz [root@472322 tmp]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6 ...

  3. BZOJ 1023

    program bzoj1023; uses math; ; maxn=; maxm=; type edge=record togo,next:longint; end; var n,m,cnt,in ...

  4. [置顶] 使用mongofiles操作GridFS

    使用mongofiles操作GridFS GridFS描述: GridFS,看起来像一种文件系统,其实是一种数据库用法.主要用来在数据库中存储二进制大文件.可以统一用数据库处理数据,而无需借助外部的文 ...

  5. Android记录4--自定义ToggleButton+用SharedPreferences保存用户配置

    Android记录4--自定义ToggleButton+用SharedPreferences保存用户配置 2013年8月14日Android记录 很多应用都会有用户设置,用户的一些偏好可以由用户来决定 ...

  6. CodeFirst-Section1之小例子

    尽可能做到不说一些晦涩难懂的语言,Follow Me...... 环境:Visual Studio 2013+.Net Framework 4.5 1.什么是Code First? 说白了就是先建好C ...

  7. JavaSE学习总结第12天_API常用对象2

      12.01 Scanner的概述和构造方法原理 Scanner类概述:JDK5以后用于获取用户的键盘输入 构造方法:public Scanner(InputStream source) publi ...

  8. json所需jar包 & js解析后台json数据

    Json 所需jar包: var listxxx='<%=request.getAttribute("listxxx")%>';  // list数组 var mapx ...

  9. ThinkPHP第八天(U函数放置在外部JS不会被解析,错误界面定制,错误信息变量)

    1.JS外部文件中U函数不会被解析,内部JS代码可以被解析. 2.halt. _404可以定制错误模板,在配置文件中配置 TMPL_EXCEPTION_FILE =>'./Public/Tpl/ ...

  10. http://riddle.arthurluk.net walkthrough

    MSVFMyU4MCU4MWh0dHAlM0ElMkYlMkZyaWRkbGUuYXJ0aHVybHVrLm5ldCUyRnN0YWdlb25lLnBocCUwRCUwQTIlRTMlODAlODFo ...