Cod sursa(job #2745129)

Utilizator mafiotxrobeert mafiotx Data 25 aprilie 2021 22:04:54
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream> 
#include <fstream>
#include <iomanip>
#include <cmath>
#include <algorithm> 
#include <cstring>

using namespace std;

string NumeFisier = "fractii";

ifstream fin(NumeFisier + ".in");
ofstream fout(NumeFisier + ".out");

typedef unsigned long long int ull;

const int len = 10e6;
long totien[len + 1];

void TOTIEN()
{
	for (int i = 1; i <= len; i++)
		totien[i] = i;

	for (int i = 2; i <= len; i++) 
	{
		if (totien[i] == i)
		{
			totien[i]--;
			for (int j = 2; j * i <= len; j++)
				totien[i * j] = totien[i * j] / i * (i - 1);
		}
	}
}

int main()
{
	TOTIEN();
	int n;
	fin >> n;
	long long nrFractii = 1;
	for (int i = 2; i <= n; i++)
		nrFractii += 2 * totien[i];
	fout << nrFractii;
}