You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
558 B
23 lines
558 B
#include <bits/stdc++.h>
|
|
|
|
//https://www.jianshu.com/p/f16d318efe9b
|
|
using namespace std;
|
|
|
|
const int N = 1000000;
|
|
int check[N];//元素值为0代表是素数
|
|
int prime[N];
|
|
|
|
int main() {
|
|
int cnt = 0;
|
|
for (int i = 2; i < N; i++) {
|
|
//如果是素数
|
|
if (!check[i]) prime[cnt++] = i;
|
|
for (int j = 0; j < cnt && i * prime[j] < N; j++) {
|
|
check[i * prime[j]] = 1;//筛掉
|
|
if (i % prime[j] == 0) break;
|
|
}
|
|
}
|
|
printf("%.2f", (double) clock() / CLOCKS_PER_SEC);
|
|
return 0;
|
|
}
|