Cod sursa(job #1925206)

Utilizator danutmafteiMaftei Danut danutmaftei Data 12 martie 2017 17:02:47
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>
#define MAX 1000001

using namespace std;

ifstream fin("fractii.in");
ofstream fout("fractii.out");
int n,phi[MAX];


void read()
{
    fin>>n;
}

void pozphi()
{
    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];
}

void suma()
{
    int s=0;
    for(int i=1;i<=n;++i)
        s+=phi[i];
    fout<<2*s+1;
}

int main()
{
    read();
    pozphi();
    suma();
    return 0;
}