Cod sursa(job #1662068)

Utilizator BrandonChris Luntraru Brandon Data 24 martie 2016 14:22:01
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>

using namespace std;

ifstream cin("fractii.in");
ofstream cout("fractii.out");

int erath[1000005];
int n, ans;

int main() {
    cin >> n;

    for(int i = 1; i <= n; ++i) {
        erath[i] = i - 1;
    }

    for(int i = 2; i <= n / 2 + 1; ++i) {
        /*if(erath[i] < i - 1) {
            continue;
        }*/

        for(int j = 2 * i; j <= n; j += i) {
            erath[j] -= erath[i];
        }
    }

    for(int i = 1; i <= n; ++i) {
        ans += erath[i];
    }

    ans *= 2;
    ++ans;
    cout << ans << '\n';
    return 0;
}