Cod sursa(job #2916259)
| Utilizator | Data | 28 iulie 2022 18:07:41 | |
|---|---|---|---|
| Problema | Fractii | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.59 kb |
#include <fstream>
std::ifstream in("fractii.in");
std::ofstream out("fractii.out");
int64_t sieve[1000001], sievetot[1000001];
int main() {
int64_t x;
in >> x;
for (int i = 2; i <= x; i++) sievetot[i] = i;
for (int i = 2; i <= x; i++) {
if (sieve[i]) continue;
for (int j = 2 * i; j <= x; j += i) sieve[j] = 1;
for (int j = i; j <= 1000000; j += i) {
sievetot[j] *= i - 1;
sievetot[j] /= i;
}
}
int64_t answer = 1;
for (int64_t i = 2; i <= x; i++) answer += 2 * sievetot[i];
out << answer;
}