prithivMLmods/Coder-Stat huggingface dataset:
Problem p03418 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, s, e) for (int i = int(s); i < int(e); i++)
#define FORIT(i, c)                                                            \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int SURP = 1000000007;

int main() {
  int N, K;
  cin >> N >> K;
  long long int ret = 0;

  FOR(i, 1, N + 1) {
    FOR(j, 1, N + 1) {
      if (i % j >= K)
        ret++;
    }
  }

  cout << ret << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, s, e) for (int i = int(s); i < int(e); i++)
#define FORIT(i, c)                                                            \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int SURP = 1000000007;

int main() {
  int N, K;
  cin >> N >> K;
  long long int ret = 0;

  FOR(i, 1, N + 1) {
    int p = N / i;
    int r = N % i;
    ret += p * max(0, i - K);
    if (K == 0) {
      ret += max(0, r - K);
    } else {
      ret += max(0, r - K + 1);
    }
  }

  cout << ret << endl;
  return 0;
}
Problem p03418 (Python)

Buggy submission (status: Time Limit Exceeded):
n, k = map(int, input().split())

ans = 0
if k == 0:
    ans = n**2
else:
    for b in range(k + 1, n + 1):
        for a in range(k, b):
            ans += ((n - a) // b) + 1

print(ans)


Fixed submission:
n, k = map(int, input().split())

ans = 0
if k == 0:
    ans = n**2
else:
    for b in range(k + 1, n + 1):
        ans += (b - k) * (n // b)
        last_count = n % b - k + 1
        ans += last_count if last_count > 0 else 0

print(ans)
Problem p03418 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, s = 0;
  scanf("%d%d", &n, &m);
  if (n <= m)
    printf("%d", 0);
  for (i = m; i <= n; i++) {
    for (j = m; j <= n; j++) {
      if (i == j)
        continue;
      if (j % i >= m) {
        s++;
        // printf("%d %d\n",j,i);
      }
    }
  }
  printf("%d", s);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i;
  long long s = 0;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++)
    s += n / i * max(0, i - k) + max(0, n % i - k + 1);
  if (k == 0)
    s -= n - k;
  printf("%lld", s);
  return 0;
}
Problem p03418 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif
  int n, k;
  cin >> n >> k;
  int s = 0;
  for (int i = k; i <= n; i++) {
    s += (i - k) * (n / i);
    s += max(n % i - (k - 1), 0LL);
  }
  if (k == 0)
    s -= n;
  cout << s;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif
  int n, k;
  cin >> n >> k;
  int s = 0;
  for (int i = max(1LL, k); i <= n; i++) {
    s += (i - k) * (n / i);
    s += max(n % i - (k - 1), 0LL);
  }
  if (k == 0)
    s -= n;
  cout << s;
}
Problem p03419 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define dbg(x) cout << #x << "=" << x << "\n"
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  if (n > m)
    swap(n, m);
  if (n == 1 && m == 1)
    return puts("1");
  if (n == 1)
    return !printf("%d\n", m - 2);
  else
    printf("%lld\n", 1ll * (n - 2) * (m - 2));
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define dbg(x) cout << #x << "=" << x << "\n"
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  if (n > m)
    swap(n, m);
  if (n == 1 && m == 1)
    return !puts("1");
  if (n == 1)
    return !printf("%d\n", m - 2);
  else
    printf("%lld\n", 1ll * (n - 2) * (m - 2));
  return 0;
}
Problem p03419 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i, a, b) for (register sign i = (sign)a; i <= (sign)b; ++i)
#define Fordown(i, a, b) for (register sign i = (sign)a; i >= (sign)b; --i)
bool cmax(sign &a, sign b) { return (a < b) ? a = b, 1 : 0; }
bool cmin(sign &a, sign b) { return (a > b) ? a = b, 1 : 0; }
template <typename T> T read() {
  T ans = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    f = -1, ch = getchar();
  while (isdigit(ch))
    ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar();
  return ans * f;
}
template <typename T> void write(T x, char y) {
  if (x == 0) {
    putchar('0');
    putchar(y);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static char wr[20];
  int top = 0;
  for (; x; x /= 10)
    wr[++top] = x % 10 + '0';
  while (top)
    putchar(wr[top--]);
  putchar(y);
}
void file() {
#ifndef ONLINE_JUDGE
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif
}
const int N = 100 + 5;
ll n, m;
void input() {
  n = read<ll>(), m = read<ll>();
  if (n > m)
    swap(n, m);
}
void work() {
  if (n == 1) {
    if (m == 1)
      printf("1\n");
    else
      printf("%lld\n", m - 2);
  } else
    printf("%lld\n", n * m - n * 2 - m * 2 + 4);
}
int main() {
  file();
  input();
  work();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i, a, b) for (register sign i = (sign)a; i <= (sign)b; ++i)
#define Fordown(i, a, b) for (register sign i = (sign)a; i >= (sign)b; --i)
bool cmax(sign &a, sign b) { return (a < b) ? a = b, 1 : 0; }
bool cmin(sign &a, sign b) { return (a > b) ? a = b, 1 : 0; }
template <typename T> T read() {
  T ans = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    f = -1, ch = getchar();
  while (isdigit(ch))
    ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar();
  return ans * f;
}
template <typename T> void write(T x, char y) {
  if (x == 0) {
    putchar('0');
    putchar(y);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static char wr[20];
  int top = 0;
  for (; x; x /= 10)
    wr[++top] = x % 10 + '0';
  while (top)
    putchar(wr[top--]);
  putchar(y);
}
void file() {
#ifndef ONLINE_JUDGE
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif
}
const int N = 100 + 5;
ll n, m;
void input() {
  n = read<ll>(), m = read<ll>();
  if (n > m)
    swap(n, m);
}
void work() {
  if (n == 1) {
    if (m == 1)
      printf("1\n");
    else
      printf("%lld\n", m - 2);
  } else
    printf("%lld\n", n * m - n * 2 - m * 2 + 4);
}
int main() {

  input();
  work();
  return 0;
}
Problem p03419 (Python)

Buggy submission (status: Time Limit Exceeded):
N, M = list(map(int, input().split()))
result = 0
pos = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1)]
for i in range(N):
    for j in range(M):
        num = 0
        for p in pos:
            i_dest = i + p[0]
            j_dest = j + p[1]
            if 0 <= i_dest < N and 0 <= j_dest < M:
                num += 1
        if num % 2 != 0:
            result += 1
print(result)


Fixed submission:
N, M = list(map(int, input().split()))
result = 0
if N == 1 and M == 1:
    result = 1
elif N == 1:
    result = M - 2
elif M == 1:
    result = N - 2
else:
    result = (N - 2) * (M - 2)
print(result)
Problem p03419 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

long long n, m, ans;
int main() {
  cin >> n >> m;
  ans = n * m; /*-(m-2)*2-(n-2)*2+4;*/
  if (n > 2 && m > 2) {
    ans -= n * 2 + m * 2 - 4;
    cout << ans;
    return 0;
  }
  if (n == 2) {
    if (m == 2) {
      printf("0\n");
      return 0;
    }
    if (m == 1) {
      printf("0\n");
      return 0;
    }
    cout << ans;
    return 0;
  }
  if (n == 1) {
    if (m == 1) {
      printf("1\n");
      return 0;
    }
    if (m == 2) {
      printf("0\n");
    }
    printf("%lld\n", m - 2);
    return 0;
  }
  swap(n, m);
  if (n == 2) {
    if (m == 2) {
      printf("0\n");
      return 0;
    }
    if (m == 1) {
      printf("0\n");
      return 0;
    }
    cout << ans;
    return 0;
  }
  if (n == 1) {
    if (m == 1) {
      printf("1\n");
      return 0;
    }
    if (m == 2) {
      printf("0\n");
    }
    printf("%lld\n", m - 2);
  }
  assert(false);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

long long n, m, ans;
int main() {
  cin >> n >> m;
  printf("%lld\n", abs((n - 2) * (m - 2)));
  return 0;
}
Problem p03419 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()    // 昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9 + 7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI; // VI a(n);
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VVI; // VVI a(n,vector<int>(m)) n * m
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP; // MP a;
typedef vector<pair<int, int>> PS;
typedef long long ll; // ll とdoubleは違う
template <class T>    // chmax(max, a);
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> // chmin(min,a)
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

int main() {
  ll b, c, x, y, n, m, h, k, max = -10000000, min = 1000000000, ans = 0,
                             sum = 0;
  string s, t;
  cin >> n >> m;
  VVI a(n + 2, vector<int>(m + 2));
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      a[i - 1][j - 1]++;
      a[i - 1][j]++;
      a[i - 1][j + 1]++;

      a[i][j - 1]++;
      a[i][j]++;
      a[i][j + 1]++;

      a[i + 1][j - 1]++;
      a[i + 1][j]++;
      a[i + 1][j + 1]++;
    }
  }

  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (a[i][j] % 2 != 0)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()    // 昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9 + 7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI; // VI a(n);
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VVI; // VVI a(n,vector<int>(m)) n * m
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP; // MP a;
typedef vector<pair<int, int>> PS;
typedef long long ll; // ll とdoubleは違う
template <class T>    // chmax(max, a);
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> // chmin(min,a)
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

int main() {
  ll b, c, x, y, n, m, h, k, max = -10000000, min = 1000000000, ans = 0,
                             sum = 0;
  string s, t;
  cin >> n >> m;
  cout << abs(n * m - (m * 2 + (n - 2) * 2)) << endl;
  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
// D.

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
  LL n, k, ans = 0;
  cin >> n >> k;
  for (LL b = k + 1; b <= n; ++b) {
    LL c = n / b;
    ans += (b - k) * c;
    for (LL d = b * c + 1; d <= n; ++d) {
      ans += (d % b) >= k;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
// D.

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
  LL n, k, ans = 0;
  cin >> n >> k;
  for (LL b = k + 1; b <= n; ++b) {
    LL c = n / b;
    ans += (b - k) * c;
    LL r = n % b;
    if (r >= k) {
      ans += k ? (r - k + 1) : r;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repo(i, n) for (int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL << 61;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P) {
  if (P == 0)
    return 1;
  if (P % 2 == 0) {
    ll t = jou(N, P / 2);
    return t * t % mod;
  }
  return (N * jou(N, P - 1)) % mod;
} // jou(n,mod-2)で逆元
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//   cout << fixed << setprecision (20);   小数点以下2０桁まで
// 実行時間制約2秒では２×10^8回くらいまで計算できる

int main() {
  ll n, k;
  cin >> n >> k;

  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }

  ll ans = 0;
  for (ll i = k + 1; i <= n; i++) {
    for (ll j = k; j < i; j++) {
      ans += (n - j) / i + 1;
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repo(i, n) for (int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL << 61;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P) {
  if (P == 0)
    return 1;
  if (P % 2 == 0) {
    ll t = jou(N, P / 2);
    return t * t % mod;
  }
  return (N * jou(N, P - 1)) % mod;
} // jou(n,mod-2)で逆元
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//   cout << fixed << setprecision (20);   小数点以下2０桁まで
// 実行時間制約2秒では２×10^8回くらいまで計算できる

int main() {
  ll n, k;
  cin >> n >> k;

  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }

  ll ans = 0;
  for (ll i = k + 1; i <= n; i++) {
    ans += ((n - k) / i + 1) * (i - k);
    ans -= max((((n - k) / i) * i + i - 1 - n), 0ll);
  }

  cout << ans << endl;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define IFOR(i, m, n) for (int i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

int main() {
  ll N, K;
  cin >> N >> K;

  if (K == 0) {
    cout << (ll)N * N << endl;
    return 0;
  }

  ll ans = 0;
  FOR(b, K + 1, N + 1) FOR(r, K, b) { ans += (N - r) / b + 1; }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define IFOR(i, m, n) for (int i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

int main() {
  ll N, K;
  cin >> N >> K;

  if (K == 0) {
    cout << (ll)N * N << endl;
    return 0;
  }

  ll ans = 0;
  FOR(b, K + 1, N + 1) {
    ans += b - K;
    if (K > N % b) {
      ans += ((N - K) / b) * (b - K);
    } else {
      ans += (N % b - K + 1) * ((N - K) / b) +
             (b - (N % b) - 1) * ((N - K) / b - 1);
    }
    // DUMP(ans);
  }

  cout << ans << endl;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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

template <typename T> map<T, T> getPrimeFactor(T n) {
  map<T, T> res;
  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}

template <typename T> bool IsPrimeNumber(T num) {
  if (num <= 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }

  return true;
}

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

#define rep(i, s, e) for (ll i = s; i < e; i++)
#define repeq(i, s, e) for (ll i = s; i <= e; i++)

int main() {
  ll N, K;

  std::cin >> N >> K;
  ll ans = N * N;
  if (K > 0) {
    ans -= (K - 1) * N;
  }
  repeq(a, K, N) {
    repeq(b, 1, a) {
      if (a % b < K) {
        ans--;
      }
    }
  }
  std::cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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

template <typename T> map<T, T> getPrimeFactor(T n) {
  map<T, T> res;
  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}

template <typename T> bool IsPrimeNumber(T num) {
  if (num <= 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }

  return true;
}

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

#define rep(i, s, e) for (ll i = s; i < e; i++)
#define repeq(i, s, e) for (ll i = s; i <= e; i++)

int main() {
  ll N, K;

  std::cin >> N >> K;
  ll ans = N * N;
  repeq(b, 1, N) { ans -= N / b * min(K, b) + max(0LL, min(K - 1, N % b)); }
  std::cout << ans << endl;
  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;

#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl

/* -----  2018/03/11  Problem: ARC 091 B / Link:
 * http://arc091.contest.atcoder.jp/tasks/arc091_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N, K;

LL ans = 0LL;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N >> K;
  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }

  // FOR(i, 1, N + 1) {
  //	FOR(j, 1, N + 1) {
  //		cout << i%j << '\t';
  //	}cout << endl;
  // }
  FOR(b, K + 1, N + 1) { //
    LL ret = 0;
    ret += (b - K) * (N / b);
    FOR(a, b * (N / b), N + 1) {
      if (((a) % b) >= K)
        ret++;
    }
    ans += ret;
  }
  cout << ans << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;

#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl

/* -----  2018/03/11  Problem: ARC 091 B / Link:
 * http://arc091.contest.atcoder.jp/tasks/arc091_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N, K;

LL ans = 0LL;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N >> K;
  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }

  // FOR(i, 1, N + 1) {
  //	FOR(j, 1, N + 1) {
  //		cout << i%j << '\t';
  //	}cout << endl;
  // }
  FOR(b, K + 1, N + 1) { //
    LL ret = 0;
    ret += (b - K) * (N / b);
    ret += max(0LL, N % b - K + 1);
    ans += ret;
  }
  cout << ans << "\n";

  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(void) {
  int N, K;
  ll ret = 0;
  cin >> N >> K;

  if (K == 0)
    ret -= N;
  for (int k = K; k < N; k++) {
    ret += N - k;
    for (int b = N - k; b >= k + 1; b--) {
      ret += (N - k) / b;
    }
  }

  return !printf("%lld\n", ret);
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(void) {
  int N, K;
  ll ret = 0;
  cin >> N >> K;

  if (K == 0)
    ret -= N;
  for (int k = K; k < N; k++) {
    ret += N - k;
    int i = 1;
    for (int b = N - k; b >= k + 1; b = (N - k) / i) {
      ret += b - k;
      i++;
    }
  }

  return !printf("%lld\n", ret);
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i, a) for (auto &i : a)
typedef long long ll;
typedef pair<int, int> P;
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  FOR(i, 1, n + 1) FOR(j, 1, n + 1) if (i % j >= k) ans++;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i, a) for (auto &i : a)
typedef long long ll;
typedef pair<int, int> P;
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  if (k == 0) {
    cout << ll(n) * ll(n) << endl;
    return 0;
  }
  FOR(i, 1, n + 1) { ans += (n / i * max(0, i - k)) + max(0, n % i - k + 1); }
  cout << ans << endl;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main() {
  cin.sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }
  reps(i, K, N) { ans += N - i; }
  int x;
  reps(i, K, N + 1) {
    if (N - i < i + 1)
      break;
    reps(j, i + 1, N - i + 1) {
      x = (N - i) / j;
      ans += x;
      if (x == 1) {
        ans += (N - i + 1 - (j + 1));
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main() {
  cin.sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }
  reps(i, K, N) { ans += N - i; }
  int x;
  reps(i, K, N + 1) {
    if (N - i < i + 1)
      break;
    reps(j, i + 1, N - i + 1) {
      x = (N - i) / j;
      ans += ((N - i) / x - j + 1) * x;
      j = (N - i) / x;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) { return max(max(a, b), c); }
int Min(int(a), int(b), int(c)) { return min(min(a, b), c); }

int main() {

  ll N, K;
  cin >> N >> K;
  ll an = 0;
  rep(i, N) {
    rep(j, N) {
      if ((i + 1) % (j + 1) >= K) {
        an++;
      }
    }
  }
  cout << an << endl;
}

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) { return max(max(a, b), c); }
int Min(int(a), int(b), int(c)) { return min(min(a, b), c); }

int main() {

  ll N, K;
  cin >> N >> K;
  ll an = 0;
  for (long long i = 1 + K; i < N + 1; i++) {
    an += ((N - N % i) / i) * (i - K);
    an += max(ll(0), (N % i) - K + 1);
  }
  if (K == 0) {
    an -= N;
  }
  cout << an << endl;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  long long answer = 0;
  long long n, k;
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (long long i = k + 1; i <= n; i++) {
    long long loop = i - k;
    answer += loop * (n / i);
    for (long long j = i * (n / i); j <= n; j++) {
      if ((j % i) >= k) {
        answer++;
      }
    }
  }
  cout << answer << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long long answer = 0;
  long long n, k;
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (long long i = k + 1; i <= n; i++) {
    long long loop = i - k;
    answer += loop * (n / i);
    if ((n - (n / i) * i + 1) - k > 0) {
      answer += (n - (n / i) * i + 1) - k;
    }
  }
  cout << answer << endl;
  return 0;
}
Problem p03420 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())

    res = 0
    for b in range(K + 1, N + 1):
        p = 0
        q = K
        while b * p + q <= N:
            if b * p + q > 0:
                res += 1
            if q == b - 1:
                p += 1
                q = K
            else:
                q += 1

    print(res)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())

    res = 0
    for b in range(K + 1, N + 1):
        p = N // b
        q = N - b * p
        res += max(0, q - K + 1)
        res += p * max(0, b - 1 - K + 1)
        if K == 0:
            res -= 1

    print(res)


if __name__ == "__main__":
    main()
Problem p03420 (Python)

Buggy submission (status: Time Limit Exceeded):
import numpy as np

n, k = map(int, input().split())
ans = 0
for m in range(k, n):
    nm = n - m
    sb = m + 1
    s = nm // sb
    ds = [nm // d + 1 for d in range(s, 0, -1)]
    ds = [sb] + ds + [n + 1]
    # print(m, nm, sb, s, ds)
    dd = np.diff(ds)
    pd = np.arange(s + 1, 0, -1) if m else np.arange(s, -1, -1)
    # print(dd, pd, dd * pd, sum(dd * pd))
    ans += sum(dd * pd)
print(ans)


Fixed submission:
import numpy as np

n, k = map(int, input().split())
ans = 0
for m in range(k, n):
    nm = n - m
    sb = m + 1
    s = nm // sb
    p = s + 1 if m else s
    ps = sb
    for d in range(s, 0, -1):
        ds = nm // d + 1
        co = ds - ps
        ans += co * p
        ps = ds
        p -= 1
    ans += n + 1 - ps

    # ds = [nm // d + 1 for d in range(s, 0, -1)]
    # ds = [sb] + ds + [n + 1]
    # # print(m, nm, sb, s, ds)
    # dd = np.diff(ds)
    # pd = np.arange(s + 1, 0, -1) if m else np.arange(s, -1, -1)
    # # print(dd, pd, dd * pd, sum(dd * pd))
    # ans += sum(dd * pd)
print(ans)
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for (int i = start; i <= finish; i += k)

const int MXN = 1e6 + 200;
const long long MNN = 2e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, k, ans;

int main() {
  ios;
  cin >> n >> k;
  for (int i = k + 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j % i >= k) {
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}


Fixed submission:
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for (int i = start; i <= finish; i += k)

const int MXN = 1e6 + 200;
const long long MNN = 2e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, k, ans;

int main() {
  ios;
  cin >> n >> k;
  for (llong i = k + 1; i <= n; i++) {
    for (llong j = 0; (j * i) + k <= n; j++) {
      ans += min((j + 1) * i - 1, n) - max((j * i + k), 1LL) + 1;
    }
  }
  cout << ans;
  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;
#define MOD 1000000007LL

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  for (ll b = K + 1; b <= N; b++) {
    for (ll i = K; i < b; i++) { // 余りi
      if (i != 0)
        ans += (N - i) / b + 1LL;
      else
        ans += (N - i) / b;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;
#define MOD 1000000007LL

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  for (ll b = K + 1; b <= N; b++) {
    // bで割ってK以上余るN以下の数
    ans += N / b * (b - K);
    if (K == 0)
      ans--; // 0を除外
    ll ex = max(0LL, N % b - K + 1LL);
    ans += ex;
  }
  cout << ans << endl;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--)
#define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (ll b = k + 1; k < n + 1; b++) {
    ll add = 0;
    add = (n + 1) / b * (b - k);
    ll temp = (n + 1) - (n + 1) / b * b;
    if (temp > k)
      add += (temp - k);
    // cerr << b << " " << add << endl;
    ans += add;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--)
#define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (ll b = k + 1; b < n + 1; b++) {
    ll add = 0;
    add = (n + 1) / b * (b - k);
    ll temp = (n + 1) - (n + 1) / b * b;
    if (temp > k)
      add += (temp - k);
    // cerr << b << " " << add << endl;
    ans += add;
  }
  cout << ans << endl;
  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  long long int n, k, i, j, ans, c1;
  scanf("%lld %lld", &n, &k);
  ans = 0;
  for (i = k; i <= n; i++) {
    if (i == 0) {
      ans = n * n;
      break;
    } else {
      c1 = n / i;
      ans += (i - k) * c1;
      for (j = c1 * i + 1; j <= n; j++) {
        if (j % i >= k) {
          ans++;
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  long long int n, k, i, j, ans, c1;
  scanf("%lld %lld", &n, &k);
  ans = 0;
  for (i = k; i <= n; i++) {
    if (i == 0) {
      ans = n * n;
      break;
    }
    c1 = n / i;
    ans += (i - k) * c1;
    j = n % (c1 * i);
    if (j - k + 1 > 0) {
      ans += j - k + 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;

  ll ans;
  for (int i = k; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      ll count = (n - i) / j + 1;
      ans += count;
    }
  }

  if (k == 0)
    ans -= n;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll b = i;
    ll r = (n + 1) % b;
    ll p = (n + 1) / b;
    ans += p * max((ll)0, b - k);
    ans += max((ll)0, r - k);
  }

  if (k == 0)
    ans -= n;
  cout << ans << endl;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>

typedef long long int lli;

int main(void) {
  int n, k;
  scanf("%d%d", &n, &k);

  lli res = 0;

  if (k == 0) {
    res = n;
    res *= res;
    printf("%lld\n", res);
    return 0;
  }
  // 1 <= a = r + lb <= n
  // 1 <= lb <= n-r
  for (int b = k; b <= n; b++)
    for (int r = k; r < b; r++)
      /*printf("%d %d %d\n", a, b, (n-a)/b+1), */ res += ((n - r) / b) + 1;

  printf("%lld\n", res);
}

Fixed submission:
#include <cstdio>

typedef long long int lli;

int main(void) {
  int n, k;
  scanf("%d%d", &n, &k);

  lli res = 0;

  if (k == 0) {
    res = n;
    res *= res;
    printf("%lld\n", res);
    return 0;
  }
  // 1 <= a = r + lb <= n
  // 1 <= lb <= n-r
  for (int b = k + 1; b <= n; b++) {
    lli t = n / b * (b - k);
    res += t;
    lli l = n - n / b * b;
    if (l >= k)
      res += l - k + 1;
    // printf("%d %d %d\n", b, t, l-k+1);
  }

  printf("%lld\n", res);
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N, K;
  cin >> N >> K;

  ll ans = 0;
  if (K == 0) {
    ans = 1LL * N * N;
  } else {
    // 割られる数がK以上で、割る数が割られる数よりも大きいものは条件に当てはまる
    for (int i = K; i < N; i++)
      ans += N - i;

    // 割る数の全探索の数え上げ
    for (int i = K + 1; i <= N - K; i++) {
      int k = min(N + 1, 2 * i);
      for (int j = i + K; j < k; j++) {
        ans += (N - j) / i + 1;
      }
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N, K;
  cin >> N >> K;

  ll ans = 0;
  if (K == 0) {
    ans = 1LL * N * N;
  } else {
    // bを固定して考える
    for (int i = 1; i <= N; i++) {
      int p = N / i;
      int q = N % i;
      ans += p * max(0, i - K) + max(0, q - K + 1);
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef long long LL;
LL n, k, res;
int main() {
  scanf("%lld%lld", &n, &k);
  if (k == 0)
    printf("%lld\n", n * n);
  else {
    for (LL i = n; i >= k; i--) {
      res += (n - i);
      res += max(0LL, (i - k - (i / 2 + 1) + 1));
      LL tmp = 0;
      if ((i / 3) < k)
        continue;
      for (LL j = k + 1LL; j <= i / 2; j++) {
        if (i % j >= k)
          res++, tmp++;
      }
      // printf(" %lld %lld %lld\n", i, tmp, i / k);
    }
    printf("%lld\n", res);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef long long LL;
LL n, k, res;
int main() {
  scanf("%lld%lld", &n, &k);
  if (k == 0)
    printf("%lld\n", n * n);
  else {
    for (LL b = k + 1; b <= n; b++) {
      res += (b - k) * (n / b) + max(n % b - k + 1LL, 0LL);
    }
    printf("%lld\n", res);
  }
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main(void) {
  long n, k;
  cin >> n >> k;
  long ret = 0;
  for (long b = k + 1; b <= n; b++) {
    long c = n / b;
    if (k == 0) {
      ret--;
    }
    ret += c * (b - k);
    for (long a = c * b; a <= n; a++) {
      if (a % b >= k) {
        ret++;
      }
    }
    // printf("%ld %ld\n", b, ret);
  }
  cout << ret << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main(void) {
  long n, k;
  cin >> n >> k;
  long ret = 0;
  for (long b = k + 1; b <= n; b++) {
    long c = n / b;
    if (k == 0) {
      ret--;
    }
    ret += c * (b - k);
    long t = n - (c * b + k - 1);
    ret += t > 0 ? t : 0;
    // printf("%ld %ld\n", b, ret);
  }
  cout << ret << endl;
  return 0;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if (b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b != 0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(void) {
  ll n, k;
  cin >> n >> k;
  ll kk = (k == 0) ? 1 : k;
  ll ans = n * (n - kk + 1) - (((n + kk) * (n - kk + 1)) / 2);
  for (int i = k + 1; i <= n; i++) {
    for (int j = k; j < i and j + i <= n; j++) {
      ll x = ((n - (j + i)) / i) + 1;
      ans += x;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if (b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b != 0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(void) {
  ll n, k;
  cin >> n >> k;
  ll kk = (k == 0) ? 1 : k;
  ll ans = n * (n - kk + 1) - (((n + kk) * (n - kk + 1)) / 2);
  ll base = k + 1;
  for (ll i = 0; i + base <= n; i++) {
    ll init = 2 * k + 2 * i + 1;
    ll q = ((n - init)) / (base + i);
    if (init <= n)
      q++;
    ans += q * (i + 1);
    if (0 <= (n - (init + (base + i) * q - i) + 1))
      ans += (n - (init + (base + i) * q - i) + 1);
  }
  std::cout << ans << std::endl;
  return 0;
}