Submission #1091886

# Submission time Handle Problem Language Result Execution time Memory
1091886 2024-09-22T13:14:44 Z plagia Savrsen (COCI17_savrsen) C++14
120 / 120
464 ms 39768 KB
#include <cstdlib>
#include <iostream>

const int MM = 1e7 + 10;
int tab[MM]{};

void fill_tab() {
    for (int i = 1; i < MM; i++) {
        tab[i] = 0;  // Initialize all values to zero
    }

    for (int i = 1; i < MM; i++) {  // i is a potential divisor
        for (int j = 2 * i; j < MM; j += i) {  // add i to all multiples of i, excluding itself
            tab[j] += i;
        }
    }
}

int calculate_imperfection(const int &n) {
    return std::abs(n - tab[n]);
}

int main() {
    std::ios_base::sync_with_stdio(0);

    fill_tab();

    int a, b;
    std::cin >> a >> b;
    
    unsigned long long sum = 0;
    for (int i = a; i <= b; i++) {
        sum += calculate_imperfection(i);
    }

    std::cout << sum << std::endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 388 ms 39516 KB Output is correct
2 Correct 416 ms 39516 KB Output is correct
3 Correct 444 ms 39516 KB Output is correct
4 Correct 443 ms 39512 KB Output is correct
5 Correct 449 ms 39464 KB Output is correct
6 Correct 464 ms 39516 KB Output is correct
7 Correct 441 ms 39768 KB Output is correct
8 Correct 374 ms 39516 KB Output is correct