Cod sursa(job #2781189)

Utilizator Theodor17Pirnog Theodor Ioan Theodor17 Data 8 octombrie 2021 18:38:32
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#define ll unsigned long long
using namespace std;

ifstream cin("fractii.in");
ofstream cout("fractii.out");

const int N = 1e6;
int phi[N + 1];
int n;

void ciur(){

    for(int i = 2; i <= N; i++)
        phi[i] = i;
    
    for(int i = 2; i <= N; i++){
        if(phi[i] == i){

            phi[i]++;
            for(int j = i; j <= N; j += i)
                phi[j] = phi[j] / i * (i - 1);

        }
    }



}

int main(){

    ciur();
    cin >> n;
    ll s = 1;

    if(n == 1)
        cout << n;
    else for(int i = 2; i <= n; i++)
        s += (2LL * phi[i]);

    cout << s;

    /*

    n = 4


    i = 1 : 1, 1/2, 1/3, 1/4
    i: 2    2/3, 2/1    1/2
    i: 3    1/3, 3/2, 3/4    1/3
    i: 4    1/4, 3/4    4/1, 4/2, 4/3

    */

}