Cod sursa(job #3186337)

Utilizator Mihai00700Lalallalalal Mihai00700 Data 22 decembrie 2023 18:50:13
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
#define VALMAX 1000000
using namespace std;
int e[VALMAX + 1];
long long euler(int 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  s = 0;
  for(int i = 2;i<=n;i++){
    s += e[i];
  }
  return s;
}
int main(){
    int n;
    ifstream in("fractii.in");
    ofstream out("fractii.out");
    in>>n;
    out<<1 + 2 * euler(n)<<"\n";
    in.close();
    out.close();
    return 0;
}