Cod sursa(job #3309975)

Utilizator AndreiCod123Sitaru Mircea AndreiCod123 Data 10 septembrie 2025 22:01:56
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <bits/stdc++.h>
using namespace std;

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

const int NMAX = 1000000;
int n;
vector<int> phi(NMAX + 1);

void function_phi(int n)
{
    for (int i = 1; i <= n; i++)
        phi[i] = i;

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

int main()
{
    fin >> n;
    function_phi(n);

    long long sum = 0;
    for (int i = 1; i <= n; i++)
        sum += phi[i];

    fout << sum * 2 - 1;
    return 0;
}