Cod sursa(job #708130)

Utilizator iugasilviuIuga Silviu iugasilviu Data 6 martie 2012 14:21:42
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <stdio.h>
#include <cmath>
void computeTotient(const int n, int *tot){
int i, j;
for(i = 1;i<=n; ++i){
tot[i] = i-1;
}
for(i= 2; i<=n; ++i){
for(j = 2 * i; j<=n; j += i){
tot[j] -= tot[i];
}
}
}
long long countFractions(const int n, int *tot){
long long count = 0;
int i;
for(i=2;i<=n;++i){
count += tot[i];
}
return 1 + 2*count;
}
int main(){
freopen("fractii.in","r", stdin);
freopen("fractii.out","w", stdout);
int n;
int *tot;
scanf("%d", &n);
fclose(stdin);
tot = new int[n+1](); 
computeTotient(n, tot);
long long fractions = countFractions(n, tot);  
printf("%lld", fractions);
delete [] tot;
fclose(stdout);
return 0;
}