Ural 1086 - Cryptography

时间:2022-01-30 01:22:37
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. &period;Net使用system&period;Security&period;Cryptography&period;RNGCryptoServiceProvider类与System&period;Random类生成随机数

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

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

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

  5. &quot&semi;System&period;Security&period;Cryptography&period;CryptographicException&colon; 拒绝访问&quot&semi; 问题的解决方法

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

  6. BZOJ 1086&colon; &lbrack;SCOI2005&rsqb;王室联邦

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

  7. HDOJ&lpar;2056&rpar;&amp&semi;HDOJ&lpar;1086&rpar;

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

  8. System&period;Security&period;Cryptography&period;CryptographicException&colon; 指定了无效的提供程序类型

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

  9. &lbrack;POJ2109&rsqb;Power of Cryptography

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

随机推荐

  1. &lt&semi;td&gt&semi;&lt&semi;&sol;td&gt&semi;标签的border 样式在浏览器中显示不出来

    问题: 在一些浏览器中比如360浏览器的兼容模式下, <td style="border:1px solid red;"></td> 标签 中 的内容为空时 ...

  2. Git 恢复某个文件指定版本

    1. git reflog  找到comit id 2. git reset edf92f a.txt 3. git commit -m "ssss" 4. git checkou ...

  3. linux RTC 驱动模型分析【转】

    转自:http://blog.csdn.net/yaozhenguo2006/article/details/6824970 RTC(real time clock)实时时钟,主要作用是给Linux系 ...

  4. 基于TLS的反调试技术

    TLS(Thread Local Storage 线程局部存储) 一个进程中的每个线程在访问同一个线程局部存储时,访问到的都是独立的绑定于该线程的数据块.在PEB(进程环境块)中TLS存储槽共64个( ...

  5. PHP学习笔记-数组&lpar;1&rpar;

    1-1 数组定义 1.什么是数组? 所谓数组,就是相同数据类型的元素按一定顺序排列的集合,就是把有限个类型相同的变量用一个名字命名,然后用编号区分他们的变量的集合,这个名字称为数组名,编号称为下标.组 ...

  6. Codecs是以plugin的形式被调用的(显示中文的codec plugin文件是qcncodecs4&period;dll),可静态载入和动态载入

    作为非英语国家人员开发的类库,QT有充分的理由优先考虑支持Unicode和各国自定义字库编码.大家也知道了QT对软件Internationalization有一套完整的开发模型,包括专门为此写的lin ...

  7. JCronTab 定时调用

    习惯使用 unix/linux 的开发者应该对 crontab 都不陌生.Crontab 是一个很方便的用于 unix/linux 系统的任务调度命令.JCronTab 则是一款全然依照 cronta ...

  8. android&period;view&period;WindowManager&dollar;BadTokenException&colon; Unable to add window — token null is not for an applic

    之前遇到过这样的问题, 04-12 10:40:33.302: E/AndroidRuntime(17213): Caused by: android.view.WindowManager$BadTo ...

  9. Javascript&colon;scrollWidth&comma;clientWidth&comma;offsetWidth的区别(转)

    网页可见区域宽:document.body.clientWidth; 网页可见区域高:document.body.clientHeight; 网页可见区域高:document.body.offsetW ...

  10. PostgreSQL学习笔记&lpar;二&rpar;-安装pgAdmin

    继上篇安装PostgreSQL后,我们需要安装一个PostgreSQL的图形化管理工具. pgadmin管理工具 创建Python的虚拟环境 cd /root/venv python -m venv ...