Cod sursa(job #2868380)

Utilizator mariog901Grigore Mario mariog901 Data 10 martie 2022 21:32:55
Problema Fractii Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
// fractii_info_arena.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("fractii.in");
ofstream fout("fractii.out");

long long phi(long n)
{
	long long r = n, d = 2;
	while (n > 1)
	{
		if (n % d == 0)
		{
			r = r / d * (d - 1);
			while (n % d == 0)
				n /= d;
		}
		d++;
		if (d * d > n)
			d = n;
	}
	return r;
}

int main()
{
	long long n;
	fin >> n;
	if (n == 0) {
		fout << 0;
		return 0;
	}
	long long s = 1;

	for (long long i = 2; i <= n; i++)
		s += 2 * phi(i);

	fout << s;
}