第十届蓝桥杯——质数

【问题描述】

我们知道第一个质数是 2、第二个质数是 3、第三个质数是 5……
请你计算第 2019 个质数是多少?

【答案提交】
这是一道结果填空的题,你只需要算出结果后提交即可。
本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。


题解:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

bool judge(int n)
{
	for (int i = 2; i < n; i ++) if(n % i == 0) return false;
	return true;
}
int main()
{
	int cnt = 0;
	for (int i = 2; i < 100000; i ++)
        if(judge(i))
        {
	        cnt ++;
	        if(cnt == 2019) cout << i << endl;
	    }
	
	return 0;
}

答案:17569

如果感觉这篇文章对你有帮助的话,不妨点一个赞,十分感谢(✪ω✪)。
printf(“点个赞吧!”);
cout <<“点个赞吧!”;
System.out.println(“点个赞吧!”);
↓↓↓

发布了63 篇原创文章 · 获赞 5 · 访问量 828

猜你喜欢

转载自blog.csdn.net/weixin_46239370/article/details/105441551
今日推荐