Pagini recente » Cod sursa (job #2818631) | Cod sursa (job #1646388) | Cod sursa (job #1944073) | Cod sursa (job #2922363) | Cod sursa (job #472063)
Cod sursa(job #472063)
#include<cstdio>
#include<cstdlib>
#include<iostream>
int totient(int N)
{
int sum = N;
for(int i = 2; i <= N; i++)
{
if(N % i == 0)
{
sum -= sum/i;
while(N % i == 0)
N /= i;
}
}
return sum;
}
int main()
{
FILE* f = fopen("fractii.in", "r");
FILE* g = fopen("fractii.out", "w");
int N;
fscanf(f, "%d", &N);
int total = 0;
for(int i = 2; i <= N; i++)
{
//printf("[totient %d %d]\n", i, totient(i));
total += totient(i);
}
total *= 2;
total++;
fprintf(g, "%d\n", total);
fclose(f);
fclose(g);
}