ural 1086. Cryptography
2013-11-02 14:27
239 查看
1086. Cryptography
Time limit: 2.0 secondMemory 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
input | output |
---|---|
4 3 2 5 7 | 5 3 11 17 |
思路:我是先将15000个素数全部算出来,采用传统的方法肯定是不行的,利用定理:一个素数的倍数一定不是素数进行计算
AC代码:
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string> using namespace std; bool kiss[164000]; int numbers[15100]={0}; int sgin=1; int main() { memset(kiss,true,sizeof(kiss)); for(int i=2;i<=164000;i++){//统计出15000个素数 if(kiss[i]){ numbers[sgin++]=i; for(int k=1;i*k<=164000;k++){ kiss[i*k]=false; } } } int T; scanf("%d",&T); while(T){//按照要求去输出 int n; scanf("%d",&n); printf("%d\n",numbers ); T--; } return 0; }
View Code
相关文章推荐
- 四、编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数。
- linux下写c程序
- 通过这些小细节看清你身边的人
- POJ P2524 Ubiquitous Religions
- Lazy Scheduler:我的轻量级任务调度框架
- java web B/s的简单实用基础总结(1)
- 似乎这种折腾也没啥意义,不过
- SQL高级查询--case表达式
- WindowsPhone7与PC平台使用TripleDES加解密
- 跨平台中对于 自旋锁(spinlock) 的包装
- setw()函数的应用
- PS技巧——用背景色檫除
- 转】未指定 INSTANCESHAREDWOWDIR 命令行值。如果指定INSTANCESHAREDDIR 值,则必须指定该值 .
- 得到kernel版本的几种方法
- 关于TIME_WAIT重用与RFC1337
- ThreadLocal的理解和使用方法
- cublasSgemm处理C中按行存储的矩阵乘法
- PHP开发者实用的代码
- HttpClient上传文件
- HDU1878无向图判断欧拉回路