hiho第九十三周

Eular质数筛法
代码如下:
#include 
#define maxn 1000010
using namespace std;
int mindiv[maxn] = {0};
int prime[maxn], prime_count = 0;
int main()
{
    int n;

    scanf( "%d", &n);
    for (int i = 2; i <= n; i++) {
        if (mindiv[i] == 0) {
            prime[prime_count++] = i;
        }
        for (int j = 0; j < prime_count && i * prime[j] <= n; j++) {
            mindiv[i * prime[j]] = prime[j];
            if (i % prime[j] == 0) break;
        }
    }
    printf( "%d\n", prime_count);
    return 0;
}


你可能感兴趣的:(平时训练,---部分分类---,数学)