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. win7 资源管理器的背景色修改

    主要参考 http://blog.sina.com.cn/s/blog_49c182c20100w3nb.html win7 通过dll修改背景色首先找到这个文件C:\Windows\Resource ...

  2. Word2007中如何插入参考文献

    很多国内的期刊杂志都只能使用word模板,导致插入参考文献成了件麻烦事,这时特别怀念Latex的便捷.于是找到一篇介绍word2007里插入参考文献的好方法,就是利用尾注的方法使文章的参考文献标号可以 ...

  3. Xamarin几十篇博客,roslyn和dotnet也开源了

    .Net 基金会 http://www.dotnetfoundation.org/ 更新的真快,刚打完2的补丁包,3就粗来了............ https://www.visualstudio. ...

  4. Hibernate Dialect must be explicitly set

    在偶然一次运行hibernate测试类的时候,出现如下错误,Exception in thread "main" org.hibernate.HibernateException: ...

  5. SPOJ LCS(Longest Common Substring-后缀自动机-结点的Parent包含关系)

    1811. Longest Common Substring Problem code: LCS A string is finite sequence of characters over a no ...

  6. iOS开发UI 篇—CAlayer层的属性

    一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property CGPoint position; 用来设 ...

  7. Windows Server 2012 安装dll到GAC

    使用Windows管理员打开PowerShell: 运行以下命令: Set-location "c:\tools\gac" [System.Reflection.Assembly] ...

  8. js中new构造函数的研究

    <javascript高级编程>里对new操作符的解释: new操作符会让构造函数产生如下变化: 1.       创建一个新对象: 2.       将构造函数的作用域赋给新对象(因此t ...

  9. C# inherit

    Case:class A has a construct. class B is inherit from class A and B also has a construct. What's the ...

  10. PreTranslateMessage和TranslateMessage区别(转)

    PreTranslateMessage是消息在送给TranslateMessage函数之前被调用的,绝大多数本窗口的消息都要通过这里,比较常用,当需要在MFC之前处理某些消息时,常常要在这里添加代码. ...