Cod sursa(job #2279233)

Utilizator laraamy16Cioc Amelia laraamy16 Data 9 noiembrie 2018 10:49:00
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fractii.in");
ofstream g("fractii.out");
int phi[1000001], n;
long long s = 0;
void Phi(int n) {
    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];
}
int main() {
    Phi(1000000);
    f >> n;
    for(int i = 2; i <= n; i++)
        s += phi[i];
    g << 2 *s+1;
    return 0;
}