1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include <bits/stdc++.h> using namespace std;
using int64 = long long;
int main() { ios::sync_with_stdio(false); cin.tie(nullptr);
const int N = 20000000; const int K = 15000000; const int NK = N - K;
vector<int> primes; vector<bool> is_composite(N + 1, false);
for (int i = 2; i <= N; ++i) { if (!is_composite[i]) primes.push_back(i); for (int p : primes) { if ((int64)i * p > N) break; is_composite[i * p] = true; if (i % p == 0) break; } }
auto count_exp = [&](int n, int p) { int64 cnt = 0; while (n) { n /= p; cnt += n; } return cnt; };
int64 answer = 0;
for (int p : primes) { int64 e = count_exp(N, p) - count_exp(K, p) - count_exp(NK, p);
if (e > 0) { answer += (int64)p * e; } }
cout << answer << '\n'; return 0; }
|