Pagini recente » Cod sursa (job #123092) | Cod sursa (job #1470708) | Cod sursa (job #261664) | Monitorul de evaluare | Cod sursa (job #472079)
Cod sursa(job #472079)
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#define DMAX 1000001
int* totient = new int[DMAX];
int main()
{
FILE* f = fopen("fractii.in", "r");
FILE* g = fopen("fractii.out", "w");
int N;
fscanf(f, "%d", &N);
unsigned long long total = 0;
for(int i = 2; i <= N; i++)
{
totient[i] = i;
}
for(int i = 2; i <= N; i++)
{
if(totient[i] == i)
for(int j = i; j <= N; j+=i)
totient[j] -= totient[j]/i;
}
for(int i = 2; i <= N; i++)
{
printf("[totient[%d] %d]\n", i, totient[i]);
total += totient[i];
}
total *= 2;
total++;
fprintf(g, "%llu\n", total);
fclose(f);
fclose(g);
}