Cod sursa(job #3343456)

Utilizator batasAndrei Batis batas Data 27 februarie 2026 15:06:20
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
using namespace std;

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

const int DIM = 1e6 + 5;
int n;
long long ans;
int phi[DIM];

void Compute(int n);

int main()
{
	fin >> n;
	Compute(n);
	
	for (int i = 2; i <= n; ++i)
		ans += phi[i];
		
	fout << (1LL * ans * 2 + 1);
	
	return 0;
}

void Compute(int n)
{
	for (int i = 1; i <= n; ++i)
		phi[i] = i;
		
	for (int i = 2; i <= n; ++i)
		if (phi[i] == i)
		{
			phi[i]--;
			for (int j = 2; i * j <= n; ++j)
				phi[j * i] = phi[j * i] / i * (i - 1);
		}
}