题目链接:
Prime Numberhttps://www.nowcoder.com/share/jump/437195121691717713466
描述
Output the k-th prime number.
输入描述:
k≤10000
输出描述:
The k-th prime number.
示例1
输入:
3 7
输出:
5 17
源代码:
#include<iostream>
#include<cmath>
using namespace std;//习题6.6 Prime Number
bool isPrime(int n) {if (n == 1) {return false;}for (int i = 2; i <= sqrt(n); i++) {if (n % i == 0) {return false;}}return true;
}int main()
{int n;while (cin >> n) {int num = 0, number = 1;while (number++) {if (isPrime(number) == true) {num++;}if (num == n) {break;}}cout << number << endl;}return 0;
}// 64 位输出请用 printf("%lld")