Cod sursa(job #2238029)
Utilizator | Alex Anton tangerine515 | Data | 4 septembrie 2018 11:48:55 |
---|---|---|---|
Problema | Fractii | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <fstream>
int* phi;
std::fstream fi ("fractii.in", std::ios::in);
std::fstream fo ("fractii.out", std::ios::out);
int main (void) {
unsigned n;
unsigned long long res = 0;
fi >> n;
phi = (int*) malloc ((n + 10) * sizeof (int));
for (unsigned i = 2; i <= n; ++i)
phi[i] = i - 1;
for (unsigned i = 2; i <= n; ++i) {
for (unsigned j = (i << 1); j <= n; j += i)
phi[j] -= phi[i];
res += phi[i];
}
fo << (res << 1) + 1;
free (phi);
return 0;
}