Cod sursa(job #2640987)

Utilizator OvidRata Ovidiu Ovid Data 9 august 2020 14:55:36
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, fi[1000010];
bool v[1000010];
ifstream fin("fractii.in"); ofstream fout("fractii.out");
#define cin fin
#define cout fout


int32_t main(){
INIT
cin>>n;
int res=0;
for(int i=2; i<=n; i++){
    if(!v[i]){
        v[i]=true;
        fi[i]=i-1;
        for(int j=i*i; j<=n; j*=i){
            v[j]=true;
            fi[j]=(j-j/i);
        }
    }

    for(int j=2;(i*j<=n); j++){
             if( (v[i*j]==false) && (v[j]==true) ){   v[i*j]=true;
            fi[i*j]=fi[j]*fi[i];}
        }
    res+=2*fi[i];
}
cout<<res+1;



return 0;
}