Cod sursa(job #2715639)

Utilizator andreipatachiAndrei Patachi andreipatachi Data 3 martie 2021 22:26:16
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <bits/stdc++.h>
#define ll long long

using namespace std;


void solve() {
	int n, a[1000005];
	cin >> n;

	ll ans = 0;

	for(int i = 2; i <= n; i++) a[i] = i - 1;

	for(int i = 2; i <= n; i++) {
        ans += a[i];

        for(int j = 2 * i; j <= n; j += i) a[j] -= a[i];
	}

	cout << 2 *ans + 1 << '\n';
}


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

    freopen("fractii.in" , "r", stdin );
	freopen("fractii.out", "w", stdout);

    int t = 1;

	//cin >> t;

	while(t--) {
		solve();
	}
}