Cod sursa(job #2928958)

Utilizator raresgherasaRares Gherasa raresgherasa Data 24 octombrie 2022 12:24:24
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("fractii.in");
ofstream fout ("fractii.out");

const int NM = 1e6 + 5;

long long f[NM];

void precalc(){
  for (int i = 2; i <= NM; i++){
    f[i] = i;
  }
  for (int i = 2; i <= NM; i++){
    if (f[i] == i){
      for (int j = 1; j * i <= NM; j++){
        f[i * j] = f[i * j] / i * (i - 1);
      }
    }
  }
  for (int i = 2; i <= NM; i++){
    f[i] += f[i - 1];
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  precalc();
  int x; fin >> x;
  fout << 2 * f[x] + 1;
}