Cod sursa(job #3281441)

Utilizator nusuntvictorVictor Stefan nusuntvictor Data 1 martie 2025 15:54:50
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f  // INF mare pentru long long
using namespace std;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ifstream f("fractii.in");
    ofstream g("fractii.out");
    int n;
    unsigned long long ans=1;
    f>>n;
    vector<int>cnt(n+1,1e9);

    for(int i=2; i<=n; ++i)
        cnt[i]=i-1;
    for(int i=2 ; i<=n; ++i){
        ans+=2*cnt[i];
        for(int j=2*i; j<=n; j+=i)
            cnt[j]-=cnt[i];
    }
    g<<ans;

    return 0;
}