0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-20 10:45:25 +00:00
OI-codes/POJ/3292/3292.cpp

40 lines
837 B
C++
Raw Normal View History

2022-04-18 08:23:06 +00:00
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6;
int n, p, h_primes[N + 5], sum[N + 5];
bool not_h_prime[N + 5], is_h_semi_prime[N + 5];
int main() {
std::ios::sync_with_stdio(false);
for (int i = 5; i <= N; i += 4) {
if (!not_h_prime[i]) {
h_primes[++p] = i;
for (int j = i * 5; j <= N; j += i * 4) {
not_h_prime[j] = true;
}
}
}
for (int i = 1; i <= p; i++) {
for (int j = 1; j <= i && h_primes[i] * h_primes[j] <= N; j++) {
is_h_semi_prime[h_primes[i] * h_primes[j]] = true;
}
}
for (int i = 1; i <= N; i++) {
sum[i] = sum[i - 1] + is_h_semi_prime[i];
}
while (cin >> n, n) {
cout << n << ' ' << sum[n] << endl;
}
return 0;
}