Cod sursa(job #2955645)

Utilizator SG2021StancuGeorge SG2021 Data 17 decembrie 2022 15:33:07
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <iostream>
#include <fstream>

using namespace std;
typedef long long int ll;
#define for0n(i,e) for(ll i = 0 ; i < e; i++)
#define for1n(i,e) for(ll i = 1 ; i < e; i++)
#define for1nt(i,e) for(ll i = 1 ; i <= e ; i++)
#define for0nt for(ll i = 0 ; i <= e ; i++)
#define NMAX 1000001
ll p[NMAX];


ifstream f("fractii.in");
ofstream g("fractii.out");

void solve(ll n){
    for(int i = 1 ; i <= n ; i++){
        p[i] = i;
    }
    for(int i = 2 ; i <= n ; i ++){
        if(p[i] == i){
            for(int j = i ; j <= n ; j += i){
                p[j] /= i ;
                p[j] *= (i-1);
            }
        }
    }
    ll ans = 1;
    for(int i = 2 ; i <= n ; i ++){
        ans += p[i] * 2;

    }
    g << ans << endl;





}
int main(){

    ll n;
    while(f >> n){
        solve(n);
    }
    return 0;






}