Cod sursa(job #3354739)

Utilizator Alex_at_gameIustin-Alexandru Frateanu Alex_at_game Data 20 mai 2026 09:40:29
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(v) begin(v), end(v)
#define al(v, l, r) begin(v) + l, begin(v) + r + 1
#define sz(v) static_cast<int>(v.size())
#define pb push_back
#define pob pop_back
#define fs first
#define sd second

constexpr int inf = 2e9;
constexpr ll infll = 4e18;
constexpr int N = 1e6 + 5;

int n, phi[N];
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    freopen("fractii.in", "r", stdin);
    freopen("fractii.out", "w", stdout);

    cin >> n;
    iota(al(phi, 1, n), 1);

    for (int i = 2; i <= n; ++i) {
        if (phi[i] != i) {
            continue;
        }

        for (int j = i; j <= n; j += i) {
            phi[j] -= phi[j] / i;
        }
    }

    ll ans = -1; ///ca sa nu numaram 1/1 de 2 ori
    for (int i = 1; i <= n; ++i) {
        ans += phi[i] << 1;
    }

    cout << ans << "\n";
}