Pagini recente » Cod sursa (job #2375656) | Cod sursa (job #3265003) | Cod sursa (job #2909960) | Cod sursa (job #2278607) | Cod sursa (job #3265384)
#include <stdio.h>
#define FIN "fractii.in"
#define FOUT "fractii.out"
void computePHI(int n, int *ptr) {
int phi[n+1];
int sum = 0;
for(int i = 1; i <= n; ++i) phi[i] = i;
for(int i = 2; i <= n; ++i) {
//daca este numar prim
if(phi[i]==i) {
for(int j = i; j <= n; j+=i) {
phi[j] = phi[j] / i * (i - 1);
}
}
sum+=phi[i];
}
*ptr=(sum<<1)+1;
}
int main(int argc, char const *argv[]) {
int n, ans;
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
scanf("%d",&n);
computePHI(n,&ans);
printf("%d",ans);
return 0;
}