Cod sursa(job #2373159)

Utilizator MichaelXcXCiuciulete Mihai MichaelXcX Data 7 martie 2019 12:32:31
Problema Fractii Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include    <iostream>
#include    <fstream>

#define     NMAX 1000005
#define     ll long long

using namespace std;

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

ll n;
int v[NMAX];
int fractii(int n)
{
    ll cnt = 0;
    for(int i = 2; i <= n; i++)
        v[i] = i-1;
    for(int i = 2; i <= n/2; i++)
        for(int j = 2*i; j <= n; j+=i)
        v[j] -= v[i];
    for(int i = 2; i <= n; i++)
        cnt+=v[i];

    return (2*cnt+1);
}

int main()
{
    fin >> n;
    fout << fractii(n);
    return 0;
}