Submission #969639

# Submission time Handle Problem Language Result Execution time Memory
969639 2024-04-25T11:50:57 Z RandomUser Savrsen (COCI17_savrsen) C++17
120 / 120
1247 ms 49580 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 1e7 + 5;

bool sieve[maxn+1];
int mpf[maxn+1];

ll exp(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b & 1) ans = ans * a;
        a = a * a;
        b /= 2;
    }
    return ans;
}

int main() {
    for(int i=2; i<=maxn; i++) {
        if(sieve[i]) continue;
        mpf[i] = i;
        for(int j=2*i; j<=maxn; j+=i) {
            sieve[j] = i;
            mpf[j] = i;
        }
    }

    int l, r;
    ll ans = 0;
    cin >> l >> r;

    for(int i=l; i<=r; i++) {
        map<int, int> cnt;
        int x = i;
        while(x > 1) {
            cnt[mpf[x]]++;
            x /= mpf[x];
        }

        ll div = 1;

        for(auto &[d, c] : cnt)
            div *= ((exp(d, c+1) - 1) / (d - 1));
        ans += abs((ll)i - (div - i));
    }

    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 194 ms 49240 KB Output is correct
2 Correct 183 ms 49240 KB Output is correct
3 Correct 210 ms 49488 KB Output is correct
4 Correct 179 ms 49580 KB Output is correct
5 Correct 1138 ms 49328 KB Output is correct
6 Correct 1247 ms 49328 KB Output is correct
7 Correct 1141 ms 49336 KB Output is correct
8 Correct 457 ms 49240 KB Output is correct