Cod sursa(job #1534796)

Utilizator george.stefanGeorge Stefan george.stefan Data 23 noiembrie 2015 23:19:05
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int phi[1000000];

int main()
{
    freopen("fractii.in", "r", stdin);
    freopen("fractii.out", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;

    cin >> n;

    long long suma = 0;

    for (int i = 1; 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];

            suma += phi[i];
        }

    printf("%lld", 2 * suma + 1);

    return 0;
}