답안 #1105928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105928 2024-10-28T12:48:52 Z DangKhoizzzz Savrsen (COCI17_savrsen) C++14
30 / 120
104 ms 79692 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e7;
int sieve[MAXN + 5];

void init() {
    memset(sieve, 0, sizeof(sieve));
    for(int i = 2; i*i <= MAXN; i++) {
        if(sieve[i] != 0) continue;
        sieve[i] = i;
        for(int 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 39504 KB Output is correct
2 Correct 48 ms 39504 KB Output is correct
3 Runtime error 97 ms 79688 KB Execution killed with signal 8
4 Runtime error 101 ms 79692 KB Execution killed with signal 8
5 Runtime error 101 ms 79688 KB Execution killed with signal 8
6 Runtime error 99 ms 79688 KB Execution killed with signal 8
7 Runtime error 101 ms 79692 KB Execution killed with signal 8
8 Runtime error 104 ms 79688 KB Execution killed with signal 8