Cod sursa(job #1474136)

Utilizator aimrdlAndrei mrdl aimrdl Data 21 august 2015 00:27:22
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <stdio.h>
#include <string.h>

#define MAX 1000005

int n;
int totient[MAX];

void gentotient () {
	for (int i = 2; i <= n; ++i) {
		totient[i] = i-1;
	}
	
	for (int i = 2; i <= n; ++i) {
		for (int j = 2 * i; j <= n; j+=i) {
			totient[j] -= totient[i];
		}
	}
}
		 
	
int main (void) {
	freopen("fractii.in", "r", stdin);
	freopen("fractii.out", "w", stdout);
	
	scanf("%d", &n);
	gentotient();
	
	long long s = 0;
	for (int i = 2; i <= n; ++i) {
		s += (long long) totient[i];
	}
	
	s = 2 * s + 1;
	
	printf("%Ld", s);
	return 0;
}