Cod sursa(job #2441905)

Utilizator Ilie_MityIlie Dumitru Ilie_Mity Data 21 iulie 2019 20:59:50
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include<cstdio>

using namespace std;

int phi[1000001];

int main()
{
    FILE *f, *g;
    int n, i, j;
    long long int rez = 1;

    f=fopen("fractii.in", "r");

    fscanf(f, "%i", &n);

    fclose(f);

    for(i = 2; i <= n; ++i)
        phi[i] = i - 1;

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

    g=fopen("fractii.out", "w");

    fprintf(g, "%lli", rez);

    fclose(g);

    return 0;
}