답안 #466918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466918 2021-08-21T03:08:36 Z 2548631 Savrsen (COCI17_savrsen) C++17
120 / 120
507 ms 51928 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;

#define fastIO ios::sync_with_stdio(false), cin.tie(NULL)
#define forw(i, l, r) for( int i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( int i = (r) ; i >= (l) ; i-- )
#define log2i(x) (64 - __builtin_clzll(1ll * (x)) - 1)
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define Pi acos(-1.0l)
#define sz(x) int(x.size())
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define debug(x) cerr << #x << " = " << x << '\n';

const int N = 1e7 + 1;
int a, b;
ll ans = 0;
int sum[N];
bool kt[N];
vi primes;

int main() {
    fastIO;
#ifndef ONLINE_JUDGE
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
#endif

    cin >> a >> b;

    sum[1] = 1;
    forw(i, 2, b + 1) {
        if(!kt[i]) primes.emplace_back(i);
        for(int j = 0; j < sz(primes) && primes[j] * i <= b; j++) {
            kt[primes[j] * i] = true;
            if(i % primes[j] == 0) break;
        }

        sum[i] = 1;
    }

    for(auto x:primes) {
        for(ll i = x; i <= b; i *= x) {
            for(ll j = i; j <= b; j += i) {
                sum[j] = 1ll * sum[j] * (i * x - 1) / (i - 1);
            }
        }
    }

    forw(i, a, b + 1) ans += abs(sum[i] - 2 * i);
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 4 ms 844 KB Output is correct
4 Correct 478 ms 51872 KB Output is correct
5 Correct 507 ms 51860 KB Output is correct
6 Correct 500 ms 51928 KB Output is correct
7 Correct 459 ms 48008 KB Output is correct
8 Correct 109 ms 13504 KB Output is correct