1471: [蓝桥杯2019初赛]质数 【水题】

在这里插入图片描述
http://oj.ecustacm.cn/problem.php?id=1471

用筛选法

#include<cstdio>
#include<iostream>
using namespace std;
bool a[10000005]={
    
    false};
int main(void)
{
    
    
	int temp=0;
	int n=0;
	int i;
	for(i=2;i<=10000000;i++)
	{
    
    
		if(a[i]==false)
		{
    
    
			int j=2;
			temp=i;
			n++;
			while(i*j<=10000000)
			{
    
    
				temp=i*j;
				a[temp]=true;
				j++;
			}
		}
		if(n==2019)
		{
    
    
			printf("%d\n",i);//判断是不是找到了 
			break;
		}
	}
	printf("%d\n",i);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/bettle_king/article/details/115263061