Cod sursa(job #2421481)

Utilizator AlexandruabcdeDobleaga Alexandru Alexandruabcde Data 15 mai 2019 10:45:05
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>

using namespace std;

ifstream f ("fractii.in");
ofstream g ("fractii.out");

int n;

int phi[1000005];

unsigned long long sol;

int main()
{
    f >> n;

    for (int i = 1; i <= n; ++i)
        phi[i] = i - 1;
    phi[1] = 1;

    for (int i = 2; i <= n; ++i)
    {
        for (int j = i * 2; j <= n; j += i)
        {
            phi[j] = phi[j] - phi[i];
        }
    }

    for (int i = 1; i <= n; ++i)
    {
        sol = sol + phi[i];
    }

    g << 2 * sol - 1 << '\n';
    return 0;
}