Submission #1105894

# Submission time Handle Problem Language Result Execution time Memory
1105894 2024-10-28T08:54:13 Z DangKhoizzzz Savrsen (COCI17_savrsen) C++14
120 / 120
413 ms 39752 KB
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 1e7;
int sieve[MAXN + 5];
 
void init() {
    memset(sieve, 0, sizeof(sieve));
    for(long long i = 2; i <= MAXN; i++) {
        if(sieve[i] != 0) continue;
        sieve[i] = i;
        for(long long j = i * i; j <= MAXN; j += i) {
            sieve[j] = (sieve[j] == 0 ? i : sieve[j]);
        }
    }
}
long long f(int n) {
    long long res = 1;
    
    while(n > 1) {
        int d = sieve[n];
        int e = 1;
        while(n % d == 0) e++, n /= d;
        long long sum = 0, pw = 1;
        while(e--) {
            sum += pw;
            pw *= d;
        }
        res *= sum;
    }
    return res;
}
 
int main()
{
    init();
    int l, r; cin >> l >> r;
    long long res = 0;
    for(int x = l; x <= r; x++)
        res += abs(x - (f(x) - x));
    cout << res << '\n';
    return 0;
}
// sus dzhoz0 love ghmt
# Verdict Execution time Memory Grader output
1 Correct 51 ms 39564 KB Output is correct
2 Correct 51 ms 39504 KB Output is correct
3 Correct 65 ms 39752 KB Output is correct
4 Correct 50 ms 39556 KB Output is correct
5 Correct 387 ms 39560 KB Output is correct
6 Correct 413 ms 39504 KB Output is correct
7 Correct 377 ms 39504 KB Output is correct
8 Correct 140 ms 39504 KB Output is correct