Cod sursa(job #2916254)
| Utilizator | Data | 28 iulie 2022 17:54:10 | |
|---|---|---|---|
| Problema | Fractii | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.5 kb |
#include <fstream>
std::ifstream in("fractii.in");
std::ofstream out("fractii.out");
int64_t totient(int64_t x) {
int64_t n = x;
int64_t p = 2;
while (x > 1) {
if (x % p == 0) {
n *= p - 1;
n /= p;
while (x % p == 0) x /= p;
}
p++;
}
return n;
}
int main() {
int64_t answer = 1;
int64_t x;
in >> x;
for (int64_t i = 2; i <= x; i++) answer += 2 * totient(i);
out << answer;
}