답안 #109207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109207 2019-05-05T13:53:16 Z Frankenween Savrsen (COCI17_savrsen) C++17
60 / 120
425 ms 132096 KB
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define ull unsigned long long
#define pll pair<ll, ll>
#define mp make_pair
#define ll long long
#define pb push_back
#define deb(x) cout << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define ld long double
const ll mod1 = (ll)1e9 + 7;
const ll mod2 = (ll)1e9 + 9;
const ll BASE = 47;
const ll inf = (ll)1e18;
const long double e = 2.718281828459;
const long double pi = 3.141592653;
const ld EPS = 1e-9;


using namespace std;


template <class T>
istream& operator>>(istream &in, vector<T> &arr) {
    for (T &cnt : arr) {
        in >> cnt;
    }
    return in;
};


ll get_val(ll x, ll p) {
    ll i = p;
    while (x % (i * p) == 0) {
        i *= p;
    }
    return i;
}


void solve() {
    ll a, b;
    cin >> a >> b;
    vector<ll> p(b + 1, -1);
    p[1] = 1;
    for (ll i = 2; i <= b; i++) {
        if (p[i] != -1) {
            continue;
        }
        p[i] = i;
        for (ll j = i * i; j <= b; j += i) {
            p[j] = i;
        }
    }
    vector<ll> sigma(b + 1);
    sigma[1] = 1;
    for (ll i = 2; i <= b; i++) {
        ll cnt = get_val(i, p[i]);
        sigma[i] = sigma[i / cnt] * (cnt * p[i] - 1) / (p[i] - 1);
    }
    ll answer = 0;
    for (ll i = a; i <= b; i++) {
        answer += abs(i + i - sigma[i]);
    }
    cout << answer;
}


int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#else
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout.precision(30);
    ll seed = time(0);
    //cerr << "Seed: " << seed << "\n";
    srand(seed);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 9 ms 1920 KB Output is correct
4 Runtime error 425 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 385 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 393 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 389 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Correct 277 ms 40312 KB Output is correct