Cod sursa(job #1986804)

Utilizator andrei_bicaAndrei Bica andrei_bica Data 28 mai 2017 22:31:27
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <fstream>

using namespace std;

#define MAXN 1000010

int A[MAXN];
int N;

int main() {
	ifstream in("fractii.in");
	ofstream out("fractii.out");

	in >> N;
	for (int i = 1; i <= N; ++i)
		A[i] = i;
	for (int i = 2; i <= N; ++i) {
		if (A[i] != i) continue;

		for (int j = i; j <= N; j += i)
			A[j] = A[j] / i * (i - 1);
	}

	long long answer = 0LL;
	for (int i = 1; i <= N; ++i)
		answer += A[i];

	out << answer * 2LL - 1LL;
}