답안 #342803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342803 2021-01-02T21:04:36 Z alrad Savrsen (COCI17_savrsen) C++17
120 / 120
1250 ms 39532 KB
#include <bits/stdc++.h>

using namespace std;

using ld = long double;
using ull = unsigned long long;

/*
#pragma comment(linker, "/STACK:256000000")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

template <class T> inline T gcd(T a , T b) { return !a ? b : gcd(b % a , a); }
template <class T> inline T lcm(T a , T b) {return (a * b) / gcd(a , b) ; }

mt19937 rnd(time(0));

#define all(x) x.begin(), x.end()
#define debug(x) { cerr << #x << " = " << x << endl; }

void solve() {
  int L, R;
  cin >> L >> R;
  vector<int> dp(R + 1, 0);
  for (int d = 1; d <= R; d++) {
    for (int x = 2 * d; x <= R; x += d) {
      dp[x] -= d;
    }
  }
  long long ans = 0ll;
  for (int i = L; i <= R; i++) {
    ans += abs(i + dp[i]);
  }
  cout << ans << '\n';
  return;
}

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0) , cout.tie(0);
  int t = 1;
  while (t-- > 0) {
    solve();
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 1245 ms 39532 KB Output is correct
5 Correct 1249 ms 39532 KB Output is correct
6 Correct 1250 ms 39532 KB Output is correct
7 Correct 1144 ms 36332 KB Output is correct
8 Correct 216 ms 10220 KB Output is correct