Pagini recente » Cod sursa (job #2891060) | Cod sursa (job #2983116) | Cod sursa (job #2667399) | Cod sursa (job #2980491) | Cod sursa (job #2530780)
#include <bits/stdc++.h>
std::ifstream fin("fractii.in") ;
std::ofstream fout("fractii.out") ;
#define debug(x) std::cerr << (#x) << " : " << x << '\n'
const int MV = 1e6 ;
int totient[MV + 5] ;
void pre(int n) {
for(int p = 1 ; p <= n ; ++ p) {
totient[p] = p ;
}
for(int i = 2 ; i <= n ; ++ i) {
if (totient[i] == i) {
totient[i] -- ;
for (int j = i + i ; j <= n ; j += i) {
totient[j] = totient[j] / i * (i - 1) ;
}
}
}
}
int main () {
int n ; fin >> (n) ;
pre(n) ;
int ans(1) ;
for (int k = 2 ; k <= n ; ++ k) {
/// ~ debug(k) ; debug(totient[k]) ;
ans += (totient[k] * 2) ;
}
fout << ans ;
}