Cod sursa(job #2640495)

Utilizator AndreiPaval03Andrei Paval AndreiPaval03 Data 6 august 2020 16:45:51
Problema Fractii Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <bits/stdc++.h>

using namespace std;

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

int eulerTotient[1000005];

int main()
{
    int n;
    int count = 1;

    fin >> n;

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

    fout << count;

	return 0;
}