Cod sursa(job #2829589)

Utilizator ionelia.danielaIonelia Daniela ionelia.daniela Data 8 ianuarie 2022 19:30:12
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
int n, phi[1000000];
long long s = 1;

int cmmdc(int a, int b)
{
    if(a < b)
        swap(a, b);
    while(b)
    {
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int indicator_euler(int n)
{
    int cnt = 1, phi = 1, d = 2, copie = n;
    while(n > 1)
    {
        int p = 0;
        while(n % d == 0)
            n /= d, p++;
        cnt *= (p + 1);
        if(p > 0)
            phi *= ((d - 1) * pow(d, p - 1));
        d++;
        if(d * d > n)
            d = n;
    }
    if(cnt == 2)
        return copie - 1;
    return phi;
}

int main()
{
    fin >> n;
    phi[1] = 1;
    for(int i = 2; i <= n; ++i)
        phi[i] = i - 1;
    for(int i = 2; i <= n; ++i)
    {
        for(int j = 2 * i; j <= n; j += i)
            phi[j] -= phi[i];
    }
    for(int i = 2; i <= n; ++i)
        s += (2 * phi[i]);
    fout << s;
    return 0;
}