Cod sursa(job #2780947)

Utilizator andreea_chivuAndreea Chivu andreea_chivu Data 8 octombrie 2021 10:14:46
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>

using namespace std;

int e[1000001];
int main()
{
    ifstream fin("fractii.in");
    ofstream fout("fractii.out");

    int n;
    fin >> n;

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

    long long raspuns = 0;
    for(int i = 2; i <= n; i++){
        raspuns += e[i];
    }

    raspuns *= 2;
    raspuns++;

    fout << raspuns;

    fin.close();
    fout.close();
    return 0;
}