Cod sursa(job #2663741)

Utilizator cyg_dawidDavid Ghiberdic cyg_dawid Data 27 octombrie 2020 10:17:56
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <fstream>

using namespace std;
typedef long long ll;

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

const int NMAX = 1000005;
const int Nlim = 1000000;
int p[NMAX];

ll ans;
int n;

void totient() {
    ll i, j, aux;

    for(i = 2; i <= Nlim; i++) p[i] = i;

    for(i = 2; i <= Nlim; i++) {
        if(p[i] == i) {
            p[i]--;
            for(j = i << 1; j <= Nlim; j += i) {
                p[j] /= i;
                p[j] *= i - 1;
            }
        }
    }

}

int main()
{
    totient();

    fin >> n; n++;
    while(n--) ans += p[n];

    ans <<= 1;
    fout << ans + 1;
    return 0;
}