Cod sursa(job #3352639)

Utilizator Maries_MihaiMaries Mihai Maries_Mihai Data 29 aprilie 2026 20:19:01
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <bits/stdc++.h>

using namespace std;

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

#define nmax 10000005
#define minim -9999999

int n;
int ph[nmax];


void phi(){

    for(int i = 1; i <= n; i++){
        ph[i] = i;
    }

    for(int i = 2; i <= n; i++){
        if(ph[i] == i){

            for(int j = i; j <= n; j += i){
                ph[j] = ph[j] / i * (i-1);
            }
        }
    }
}

void ans(){
    long long suma = 0;

    phi();
    for(int i = 2; i <= n; i++){
        suma += 2 * ph[i];
    }

    fout << suma + 1;
}

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

    return 0;
}