Cod sursa(job #2458449)

Utilizator dey44andIoja Andrei-Iosif dey44and Data 20 septembrie 2019 17:10:25
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>

#define input "fractii.in"
#define output "fractii.out"
#define NMAX 1000005

using namespace std;
typedef long long ll;

ifstream in(input);
ofstream out(output);

int ciur[NMAX], N;

void Euler_Totient()
{
    for(int i = 1; i <= N; i++)
        ciur[i] = i - 1;
    for(int i = 2; i <= N; i++)
    {
        for(int j = i + i; j <= N; j += i)
            ciur[j] = ciur[j] - ciur[i];
    }
    /*for(int i = 1; i <= N; i++)
        out << ciur[i] << " ";
    out << "\n";*/
}

int main()
{
    in >> N;
    Euler_Totient();
    ll sol = 1;
    for(int i = 2; i <= N; i++)
        sol = sol + 2 * ciur[i];
    out << sol;
    return 0;
}