Pagini recente » Diferente pentru preoni-2006/runda-4/solutii intre reviziile 19 si 18 | Cod sursa (job #1693090) | Profil Vlad_317 | 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);
}