0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:08:47 +00:00

3292. Semi-prime H-numbers

23434836
This commit is contained in:
Baoshuo Ren 2022-04-18 16:23:06 +08:00
parent cc52218e22
commit 0d27ec8eb9
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

39
POJ/3292/3292.cpp Normal file
View File

@ -0,0 +1,39 @@
#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;
}