hohor學習日記: hiho一下 第九十三週(尤拉篩)
阿新 • • 發佈:2018-12-30
http://hihocoder.com/contest/hiho93/problem/1
存一下尤拉篩模板
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int Mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const double eps = 0.00000001;
const int INF = 0x3f3f3f3f;
bool isPrime[maxn];
int Cnt[maxn];
int prime[maxn];
void Isprime( ) {
int counter = 0;
memset(isPrime, true, sizeof(isPrime));
for (int i = 2; i < maxn; i ++) {
if(isPrime[i]) prime[++counter] = i;
Cnt[i] = counter;
for (int j = 1; j <= counter; j ++) {
if(i * prime[j] > maxn) break;
isPrime[i * prime[ j]] = false;
if(i % prime[j] == 0) break;
}
}
}
int main()
{
Isprime();
int n;
while(cin >> n) cout << Cnt[n] << endl;
return 0;
}