1561. PRIME
限制条件
时间限制: 1 秒, 内存限制: 32 兆
题目描述
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. The first prime number is 2. Can you write a program that computes the nth prime number, given a number n <= 10000?
输入格式
The input contains just one number which is the number n as described above.
The maximum value of n is 10000.
输出格式
The output consists of a single line with an integer that is the nth prime number.
样例输入
30
样例输出
113
这道题大概意思是求第n个素数是多少,比教简单,我就直接放代码吧
//1561. PRIME
//2016.11.22
#include <iostream>
using namespace std;
long long p[10001]={2,};
bool isprime(long long m) // 判断 素数
{
for(long long i=2;i*i<=m;i++)
{
if(m%i==0)
return false;
}
return true;
}
int main()
{
long long n;
cin>>n;
long long i=0,m=2; //i计算素数的个数
while(i<=n)
{
if(isprime(m))
p[i++]=m;
m++;
}
cout<<p[n-1]<<endl;
return 0;
}