Cryptography
题目大意:输入一个数n(n<=15000),要求输出第n 个素数。
题目分析:简单题,考察素数筛选法。
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn=200010;
int prime[maxn];
int pnum;
void getPrime()
{
pnum=0;
prime[pnum++]=2;
for(int i=3;i<=maxn;i+=2)
{
bool isprime=true;
int cap=sqrt((double)i)+1;
for(int j=0;j<pnum;j++)
{
if(prime[j]>=cap) break;
if(i%prime[j]==0) {isprime=false;break;}
}
if(isprime) prime[pnum++]=i;
}
}
int main()
{
getPrime();
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
printf("%d\n",prime[n-1]);
}
return 0;
}
分享到:
相关推荐
资源分类:Python库 所属语言:Python 资源全名:ural-0.28.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Ural解题思路 Ural解题思路 Ural解题思路 Ural解题思路
Pascal acm_timus_ural_1148.pas
Ural
Pascal acm_timus_ural_1099.pas
URAL3D
URAL(Timus Online Judge)部分测试数据 不全
Ural 1238 源代码 涉及算法(动态规划、贪心、DFS)
ural 题解 yuhch123。 关于yuhch123: ioi2008 金牌第一名,这是当初它做ural 第一卷时的题解
包含了ural题库中Vol_I 到Vol_III的所有题目的解题思路
部分题解 大牛出品 Vol1-3 不是很全,约有200题左右
URAL-PHA
Ural ACM 1000源代码(c++),vc++6.0在XPsp2下编译通过,Timus Online Judge再线测评通过
28. The Theoretical Background of the Ural-Altale Hypothesis The hypothesis of common origin of the Altaic languages,and even the Ural-Altaic languages,dates from the first half of the last century....
因为大三了 不弄ACM了 所以这些就删了 删之前希望可以帮到别人
This site is created and administrated by the students and graduates of the Ural Federal University. If you want to publish your problems in the archive or hold your own online programming contest, ...
大量线段树题目 zoj 1610 线段覆盖 poj 2777 线段覆盖 poj 2528 需要离散化,建树不同,需要处理不同->...ural 1019 覆盖加统计最长同一个颜色 zoj 2301 和上一题差不多,但是这个染色染的是点,注意染色为空的状况
基于张量类模板的线性代数C ++库,可用于表示等级0的张量,标量向量,1的向量,2的矩阵,3的等级3的张量等。它还包括BLAS和LAPACK子例程的接口。
chieves t he integration of optical and st ruct ural design sof tware. Mainly based on black box compo2 nent met hod , t he development of optical and st ruct ural design sof tware is completed using ...
资源分类:Python库 所属语言:Python 资源全名:ural-0.25.0-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059