Cod sursa(job #2765584)

Utilizator raulandreipopRaul-Andrei Pop raulandreipop Data 28 iulie 2021 10:35:48
Problema Fractii Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>

using namespace std;

ifstream in;
ofstream out;

int phi[1000000];

int main ()
{
    int n;
    in.open("fractii.in");
    in >> n;
    for (int i = 1; i <= n; i++)
    {
        phi[i] = i;
    }
    for (int i = 2; i <= n; i++)
    {
        if (phi[i] == i)
        {
            phi[i] --;
            for (int j = 2; j * i <= n; j ++)
            {
                phi[j * i] = phi[j * i] / i * (i - 1);
            }
        }
    }
    int ans = 1;
    for (int i = 2; i <= n; i++)
    {
        ans += (2 * phi[i]);
    }
    in.close();
    out.open("fractii.out");
    out << ans;
}