Cod sursa(job #2114273)

Utilizator torckySuciu Victor torcky Data 25 ianuarie 2018 15:43:00
Problema Fractii Scor 100
Compilator cpp Status done
Runda ichb_10 Marime 0.47 kb
#include <fstream>
#include <iostream>
using namespace std;
int v[1000005];
int main(){
    ifstream fin ("fractii.in");
    ofstream fout ("fractii.out");
    int n;
    long long int nr=1;
    fin>>n;
    for(int i=1; i<=n; i++){
        v[i]=i-1;
    }
    for(int i=1; i<=n; i++){
        for(int j=2*i; j<=n; j=j+i){
            v[j]-=v[i];
        }
    }
    for(int i=1; i<=n; i++){
        nr=nr+2*v[i];
    }
    fout<<nr<<endl;
    return 0;
}