Pagini recente » Cod sursa (job #2812108) | Cod sursa (job #2840723) | Cod sursa (job #2792413) | Cod sursa (job #2830081) | Cod sursa (job #2530343)
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma unroll
std::fstream fin("pietre.in", std::ios::in) ;
std::fstream fout("pietre.out", std::ios::out) ;
#define debug(x) std::cerr << (#x) << " : " << x << '\n'
const int MV = 1e6 ;
int totient[MV + 5] ;
void pre() {
for(int p = 1 ; p <= MV ; ++ p) {
totient[p] = p ;
}
for(int i = 2 ; i <= MV ; ++ i) {
if (totient[i] == i) {
totient[i] -- ;
for (int j = i + i ; j <= MV ; j += i) {
totient[j] = totient[j] / i * (i - 1) ;
}
}
}
}
int main () {
int n ; fin >> (n) ;
pre() ;
int ans(1) ;
for (int k = 2 ; k <= n ; ++ k) {
debug(k) ; debug(totient[k]) ;
ans += (totient[k] * 2) ;
}
fout << ans ;
}