Cod sursa(job #3217697)

Utilizator GoreaRaresGorea Rares-Andrei GoreaRares Data 24 martie 2024 13:22:19
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>
#define int long long

using namespace std;

int phi[1000001], n;

void init()
{
    int i, j;
    for(i = 2; i <= n; i++)
    {
        phi[i] = i;
    }
    for(i = 2; i <= n; i++)
    {
        if(phi[i] == i)
        {
            for(j = i; j <= n; j += i)
            {
                phi[j] = phi[j] / i * (i - 1);
            }
        }
    }
}

signed main()
{
    ifstream cin("fractii.in");
    ofstream cout("fractii.out");
    int i, rez = 1;
    cin >> n;
    init();
    for(i = 1; i <= n; i++)
    {
       rez = rez + phi[i];
    }
    cout << rez * 2 - 1;
    return 0;
}