Project Euler 007

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e7 + 10;

int tot;
int ntp[N];
int primes[N];

void sieve () {
	ntp[1] = 1;
	for(int i = 2;i < N; i ++) {
		if(!ntp[i]) {
			primes[++tot] = i;
		}
		for(int j = 1;j <= tot and i * primes[j] < N; j ++) {
			ntp[i * primes[j]] = 1;
			if(i % primes[j] == 0) break;
		}
	}
}

signed main () {
	sieve();
	cout << primes[10001] << endl;
	return 0;
}

原文链接: https://www.cnblogs.com/Allorkiya/p/15832829.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    Project Euler 007

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/187299

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 上午11:16
下一篇 2023年2月12日 上午11:16

相关推荐