Cod sursa(job #2640504)

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

using namespace std;

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

int eulerTotient[1000005];

int main()
{
    int n;
    unsigned long long 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;
}