Cod sursa(job #3202227)

Utilizator verde.cristian2005Verde Flaviu-Cristian verde.cristian2005 Data 11 februarie 2024 10:22:50
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <bits/stdc++.h>
using namespace std;

int phi[1000001];

int main()
{
    freopen("fractii.in", "r", stdin);
    freopen("fractii.out", "w", stdout);
    int n;
    cin >> n;
    for(int i = 2; 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 * (i - 1);
    long long rez = 1;
    for(int i = 2; i <= n; i++)
        rez += 2 * phi[i];
    cout << rez;
    return 0;
}