Cod sursa(job #1551272)

Utilizator dnprxDan Pracsiu dnprx Data 15 decembrie 2015 17:03:51
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <bits/stdc++.h>
#define nmax 1000005
using namespace std;

int a[nmax], n;

void Phi()
{
    int i, j;
    for (i = 1; i <= n; ++i)
        a[i] = i;
    for (i = 2; i <= n; ++i)
        if (a[i] == i)
            for (j = i; j <= n; j += i)
                a[j] = a[j] * (i - 1) / i;
}

void Citire()
{
    ifstream fin("fractii.in");
    fin >> n;
    fin.close();
}

void Afisare()
{
    int i;
    long long cnt = 0;
    for (i = 1; i <= n; ++i)
        cnt += a[i];
    cnt *= 2;
    cnt--;
    ofstream fout("fractii.out");
    fout << cnt << "\n";
    fout.close();
}

int main()
{
    Citire();
    Phi();
    Afisare();
    return 0;
}