Cod sursa(job #472079)

Utilizator marius.bucurBucur Marius - Ovidiu marius.bucur Data 22 iulie 2010 21:04:58
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#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);
}