alexjercan/bugnet huggingface dataset:
Problem p01391 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

typedef unsigned int uint;

uint xor128(void) {
  static uint x = 123456789;
  static uint y = 362436069;
  static uint z = 521288629;
  static uint w = 88675123;
  uint t;

  t = x ^ (x << 11);
  x = y;
  y = z;
  z = w;
  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

int n, k, ans[1001], card[501][1001];

bool ok(void) {

  for (int i = 0; i < k; i++) {
    int sum = 0;
    for (int j = 0; j < n / 2; j++)
      sum += ans[card[i][j] - 1];

    if (sum < n / 8 || 3 * n / 8 < sum)
      return false;
  }
  return true;
}

int main(void) {

  cin >> n >> k;

  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n / 2; j++) {
      cin >> card[i][j];
    }
  }

  while (true) {
    for (int j = 0; j < n; j++)
      ans[j] = xor128() % 2;

    if (ok()) {
      for (int j = 0; j < n; j++)
        cout << ans[j];
      cout << endl;
      break;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

typedef unsigned int uint;

uint xor128(void) {
  static uint x = 123456789;
  static uint y = 362436069;
  static uint z = 521288629;
  static uint w = 88675123;
  uint t;

  t = x ^ (x << 11);
  x = y;
  y = z;
  z = w;
  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

int n, k, ans[10], card[501][10];

bool ok(void) {

  for (int i = 0; i < k; i++) {
    int sum = 0;
    for (int j = 0; j < n / 2; j++)
      sum += ans[card[i][j] - 1];

    if (sum < n / 8 || 3 * n / 8 < sum)
      return false;
  }
  return true;
}

int main(void) {

  cin >> n >> k;

  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n / 2; j++) {
      cin >> card[i][j];
    }
  }

  while (true) {
    for (int j = 0; j < 8; j++)
      ans[j] = xor128() % 2;

    if (ok()) {
      for (int j = 0; j < 8; j++)
        cout << ans[j];
      cout << endl;
      break;
    }
  }

  return 0;
}
Problem p01391 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int a[500][500];
int v[1000];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  rep(i, k) rep(j, n / 2) scanf("%d", &a[i][j]), a[i][j]--;
  random_device rnd;
  mt19937 mt(rnd());
  while (1) {
    rep(i, n) v[i] = mt() % 2;
    rep(i, k) {
      int sum = 0;
      rep(j, n / 2) {
        sum += v[a[i][j]];
        if (sum > 3 * n / 8)
          goto g;
        if (sum + n / 2 - j - 1 < n / 8)
          goto g;
      }
    }
    rep(i, n) printf("%d", v[i]);
    puts("");
    return 0;
  g:;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int a[500][500];
int v[500];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  rep(i, k) rep(j, n / 2) scanf("%d", &a[i][j]), a[i][j]--;
  random_device rnd;
  srand(rnd());
  while (1) {
    rep(i, n) v[i] = rand() % 2;
    rep(i, k) {
      int sum = 0;
      rep(j, n) {
        sum += v[a[i][j]];
        if (sum > 3 * n / 8)
          goto g;
        if (sum + n - j - 1 < n / 8)
          goto g;
      }
    }
    rep(i, n) printf("%d", v[i]);
    puts("");
    return 0;
  g:;
  }
}
Problem p01391 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it, X) for (it = X.begin(); it != X.end(); it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int N, K, c[510][510];

int main() {
  srand(time(NULL));
  cin >> N >> K;
  rep(i, K) rep(j, N / 2) cin >> c[i][j], c[i][j]--;
  while (1) {
    int ans[1010];
    rep(i, N) ans[i] = rand() % 2;
    int ok = 1;
    rep(i, K) {
      int s = 0;
      rep(j, N / 2) s += ans[c[i][j]];
      if (s < N / 8 || 3 * N / 8 < s) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      rep(i, N) cout << ans[i];
      cout << endl;
      return 0;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it, X) for (it = X.begin(); it != X.end(); it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int N, K, c[510][510];

int main() {
  srand(time(NULL));
  cin >> N >> K;
  rep(i, K) rep(j, N / 2) cin >> c[i][j], c[i][j]--;
  while (1) {
    int ans[1010];
    rep(i, N) ans[i] = rand() % 2;
    rep(i, K) {
      int s = 0;
      if (s < N / 8 || 3 * N / 8 < s)
        goto next;
    }
    rep(i, N) cout << ans[i];
    cout << endl;
    return 0;
  next:;
  }
}
Problem p01391 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <ctime>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
int N, K, card[500][500], r[1000];
int main() {
  srand((unsigned)time(NULL));
  scanf("%d%d", &N, &K);
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < N / 2; j++) {
      scanf("%d", &card[i][j]);
    }
  }
  while (true) {
    for (int i = 0; i < N; i++)
      r[i] = rand() % 2;
    bool flag = true;
    for (int i = 0; i < K; i++) {
      int c = 0;
      for (int j = 0; j < N / 2; j++) {
        if (r[card[i][j] - 1])
          c++;
      }
      if (c < N / 8 || 3 * N / 8 < c) {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int i = 0; i < N; i++) {
        printf("%d", r[i]);
      }
      printf("\\n");
      break;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <ctime>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
int N, K, card[500][500], r[1000];
int main() {
  srand((unsigned)time(NULL));
  scanf("%d%d", &N, &K);
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < N / 2; j++) {
      scanf("%d", &card[i][j]);
    }
  }
  while (true) {
    for (int i = 0; i < N; i++)
      r[i] = rand() % 2;
    bool flag = true;
    for (int i = 0; i < K; i++) {
      int c = 0;
      for (int j = 0; j < N / 2; j++) {
        if (r[card[i][j] - 1])
          c++;
      }
      if (c < N / 8 || 3 * N / 8 < c) {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int i = 0; i < N; i++) {
        printf("%d", r[i]);
      }
      printf("\\n");
    }
  }
  return 0;
}
Problem p01391 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

  vector<int> sequence(N / 2, 0);
  sequence.resize(N, 1);

  vector<vector<int>> card(K, vector<int>(N / 2));
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < N / 2; j++) {
      cin >> card[i][j];
    }
  }

  while (1) {
    bool ok = true;
    for (int i = 0; i < K; i++) {
      int sum = 0;
      for (int j = 0; j < N / 2; j++)
        sum += sequence[card[i][j] - 1];
      if (sum < N / 8 || 3 * N / 8 < sum)
        ok = false;
    }
    if (ok)
      break;
    random_shuffle(sequence.begin(), sequence.end());
  }

  for (int i = 0; i < N; i++)
    cout << sequence[i];
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n, c, a[30], b[30], memo[30][1 << 16];

int bitcount(int bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = ((bits >> 4) + bits) & 0x0f0f0f0f;
  bits += bits >> 8;
  return (bits + (bits >> 16)) & 0xff;
}

int rec(int step, int panel) {
  if (step == n)
    return 0;
  if (memo[step][panel] >= 0)
    return memo[step][panel];

  panel |= a[step];

  int res = 0;
  for (int i = 0; i < c; i++) {
    int pushed = panel & b[i];
    res = max(res, rec(step + 1, panel ^ pushed) + bitcount(pushed));
  }

  return memo[step][panel] = res;
}

int main() {
  while (cin >> n >> c, n | c) {
    for (int i = 0; i < n; i++) {
      a[i] = 0;
      for (int j = 0; j < 16; j++) {
        int in;
        cin >> in;
        a[i] |= in << j;
      }
    }
    for (int i = 0; i < c; i++) {
      b[i] = 0;
      for (int j = 0; j < 16; j++) {
        int in;
        cin >> in;
        b[i] |= in << j;
      }
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < (1 << 16); j++)
        memo[i][j] = -1;
    cout << rec(0, 0) << endl;
  }
}
Problem p01391 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for (int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for (auto &a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, K;
  cin >> N >> K;
  int c[1010][505];
  rep(i, K) rep(j, N / 2) cin >> c[i][j];
  srand((unsigned)time(NULL));
  while (1) {
    string bin = "";
    rep(i, N) bin += '0' + rand() % 2;
    bool flag = true;
    rep(i, K) {
      int sum = 0;
      rep(j, N / 2) sum += bin[c[i][j] - 1] - '0';
      if (sum < N / 8 || 3 * N / 8 < sum)
        flag = false;
      if (!flag)
        break;
    }
    if (flag) {
      cout << bin << endl;
      break;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for (int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for (auto &a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, K;
  cin >> N >> K;
  int c[1010][505];
  rep(i, K) rep(j, N / 2) cin >> c[i][j];
  string bin = "";
  rep(i, N) bin += "0";
  while (1) {
    bool flag = true;
    rep(i, K) {
      int sum = 0;
      rep(j, N / 2) sum += bin[c[i][j] - 1] - '0';
      if (sum < N / 8 || 3 * N / 8 < sum)
        flag = false;
      if (!flag)
        break;
    }
    if (flag) {
      cout << bin << endl;
      break;
    }
    if (bin[0] == '0')
      bin[0] = '1';
    else {
      rep(i, N) {
        if (bin[i] == '1')
          bin[i] = '0';
        else {
          bin[i] = '1';
          break;
        }
      }
    }
  }
  return 0;
}
Problem p01392 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  const int N = 1100000;
  static bool cmp[N + 1] = {true, true};
  for (int i = 2; i <= N; i++) {
    if (!cmp[i]) {
      for (int j = i * 2; j <= N; j += i) {
        cmp[j] = true;
      }
    }
  }
  static int le[1000001];
  fill(begin(le), end(le), 1 << 29);
  long long A, B;
  cin >> A >> B;
  for (int i = 0; i <= N; i++) {
    if (!cmp[i]) {
      for (long long j = max<long long>(i, (A - B + i - 1) / i * i); j <= A + B;
           j += i) {
        int x = j - (A - B);
        int e = 0;
        for (long long c = j; c % i == 0; c /= i, e++)
          ;
        le[x] = (le[x] >= e) ? e : -1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < B * 2 + 1; i++) {
    ans += i + A - B >= 2 && le[i] > 0;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  const int N = 1000000;
  static bool cmp[N + 1] = {true, true};
  for (int i = 2; i <= N; i++) {
    if (!cmp[i]) {
      for (int j = i * 2; j <= N; j += i) {
        cmp[j] = true;
      }
    }
  }
  static int le[1000001];
  fill(begin(le), end(le), 1 << 29);
  long long A, B;
  cin >> A >> B;
  for (int i = 0; i <= N; i++) {
    if (!cmp[i]) {
      for (long long j = (A - B + i - 1) / i * i; j <= A + B; j += i) {
        int x = j - (A - B);
        int e = 0;
        for (long long c = j; c % i == 0; c /= i, e++)
          ;
        le[x] = (le[x] >= e) ? e : -1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < B * 2 + 1; i++) {
    ans += i + A - B >= 2 && le[i] > 0;
  }
  cout << ans << endl;
}
Problem p01392 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long

using namespace std;

bool isprime[2000001];
int fact[1000001];
bool isfox[1000001];
int factorial(ll arg, int base) {
  int ret = 0;
  while (arg % base == 0) {
    arg /= base;
    ret++;
  }
  return ret;
}

int main() {
  vector<ll> primes;
  memset(isprime, true, sizeof(isprime));
  ll a, b;
  for (int i = 2; i < 1100000; i++) {
    if (isprime[i]) {
      primes.push_back(i);
      for (int j = 2; i * j < 1100000; j++) {
        isprime[i * j] = false;
      }
    }
  }
  cin >> a >> b;
  ll len, bias;
  if (a - b < 2) {
    bias = 2;
  } else {
    bias = a - b;
  }
  len = a + b - bias + 1;

  fill((int *)fact, (int *)fact + 1000001, 1 << 29);
  memset(isfox, true, sizeof(isfox));

  for (int i = 0; i < primes.size(); i++) {
    for (int j = (primes[i] - bias % primes[i]) % primes[i]; j < len;
         j += primes[i]) {
      if (!isfox[j])
        continue;
      int tmp = factorial(j + bias, primes[i]);
      if (tmp != 0) {
        if (fact[j] == 1 << 29 || fact[j] >= tmp) {
          fact[j] = tmp;
        } else {
          isfox[j] = false;
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < len; i++) {
    res += isfox[i] ? 1 : 0;
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

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

#define ll long long

using namespace std;

bool isprime[2000001];

int factorial(ll arg, int base) {
  int ret = 0;
  while (arg % base == 0) {
    arg /= base;
    ret++;
  }
  return ret;
}

int main() {
  vector<ll> primes;
  memset(isprime, true, sizeof(isprime));
  ll a, b;
  for (int i = 2; i < 1100000; i++) {
    if (isprime[i]) {
      primes.push_back(i);
      for (int j = 2; i * j < 1100000; j++) {
        isprime[i * j] = false;
      }
    }
  }
  cin >> a >> b;
  ll len, bias;
  if (a - b < 2) {
    bias = 2;
  } else {
    bias = a - b;
  }
  len = a + b - bias + 1;
  int fact[len];
  bool isfox[len];
  fill((int *)fact, (int *)fact + len, 1 << 29);
  memset(isfox, true, sizeof(isfox));

  for (int i = 0; i < primes.size(); i++) {
    for (int j = 0; j < len; j++) {
      if (!isfox[j])
        continue;
      int tmp = factorial(j + bias, primes[i]);
      if (tmp != 0) {
        if (fact[j] == 1 << 29 || fact[j] >= tmp) {
          fact[j] = tmp;
        } else {
          isfox[j] = false;
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < len; i++) {
    res += isfox[i] ? 1 : 0;
  }
  cout << res << endl;
}
Problem p01392 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 1000007
long long A, B, W[MAX_N], cnt;
bool prime[MAX_N];
vector<short> V[MAX_N];
void primesieve() {
  for (int i = 2; i * i <= 1000000; i++) {
    for (int j = i * i; j <= 1000000; j += i)
      prime[j] = true;
  }
  for (int i = 0; i <= 1000000; i++)
    prime[i] ^= true;
}
int main() {
  cin >> A >> B;
  long long L = A - B, R = A + B;
  primesieve();
  if (L <= 0)
    L = 1;
  for (long long i = L; i <= R; i++) {
    W[i - L] = i;
  }
  for (long long i = 2; i <= 1000000; i++) {
    if (prime[i] == false)
      continue;
    long long F = (L / i) * i;
    if ((L % i) > 0)
      F += i;
    for (long long j = F; j <= R; j += i) {
      int cnts = 0;
      while (W[j - L] % i == 0) {
        W[j - L] /= i;
        cnts++;
      }
      if (cnts >= 1) {
        V[j - L].push_back(cnts);
      }
    }
  }
  for (long long i = L; i <= R; i++) {
    if (W[i - L] >= 2 && W[i - L] != i)
      V[i - L].push_back(1);
  }
  for (long long i = L; i <= R; i++) {
    bool OK = true;
    if (i <= 1LL)
      OK = false;
    for (int j = 1; j < V[i - L].size(); j++) {
      if (V[i - L][j - 1] < V[i - L][j])
        OK = false;
    }
    if (OK == true)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 1000007
long long A, B, W[MAX_N], cnt;
bool prime[MAX_N];
vector<short> V[MAX_N];
void primesieve() {
  for (int i = 2; i * i <= 1000000; i++) {
    for (int j = i * i; j <= 1000000; j += i)
      prime[j] = true;
  }
  for (int i = 0; i <= 1000000; i++)
    prime[i] ^= true;
}
int main() {
  cin >> A >> B;
  long long L = A - B, R = A + B;
  primesieve();
  if (L < 0)
    L = 1;
  for (long long i = L; i <= R; i++) {
    W[i - L] = i;
  }
  for (long long i = 2; i <= 1000000; i++) {
    if (prime[i] == false)
      continue;
    long long F = (L / i) * i;
    if ((L % i) > 0)
      F += i;
    for (long long j = F; j <= R; j += i) {
      int cnts = 0;
      while (W[j - L] % i == 0) {
        W[j - L] /= i;
        cnts++;
      }
      if (cnts >= 1) {
        V[j - L].push_back(cnts);
      }
    }
  }
  for (long long i = L; i <= R; i++) {
    if (W[i - L] >= 2 && W[i - L] != i)
      V[i - L].push_back(1);
  }
  for (long long i = L; i <= R; i++) {
    bool OK = true;
    if (i <= 1LL)
      OK = false;
    for (int j = 1; j < V[i - L].size(); j++) {
      if (V[i - L][j - 1] < V[i - L][j])
        OK = false;
    }
    if (OK == true)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p01392 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>

typedef long long lint;
using namespace std;

int fox[1100000];
bool prime[1100000];

int main() {
  lint a, b;
  lint s, t;

  scanf("%lld %lld", &a, &b);

  s = max(2ll, a - b);
  t = a + b;

  for (lint i = s; i <= t; i++)
    fox[i - s] = 999999;
  for (lint i = 3; i * i <= t; i += 2)
    prime[i] = true;
  prime[2] = true;

  for (lint i = 3; i * i <= t; i++) {
    if (prime[i]) {
      for (lint j = 3 * i; j * j <= t; j += 2 * i) {
        prime[j] = false;
      }
    }
  }
  for (lint p = 2; p * p <= t; p++) {
    if (prime[p]) {
      for (lint i = ((s + p - 1) / p) * p; i <= t; i += p) {
        if (i - s < 0)
          continue;
        lint tmp = i;
        int cnt = 0;
        while (tmp % p == 0) {
          tmp /= p;
          cnt++;
        }
        if (cnt > fox[i - s])
          fox[i - s] = -1;
        else
          fox[i - s] = cnt;
      }
    }
  }
  int ans = 0;
  for (lint i = s; i <= t; i++) {
    if (~fox[i - s])
      ans++;
  }

  printf("%d\\n", ans);

  return (0);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>

typedef long long lint;
using namespace std;

int fox[1100000];
bool prime[1100000];

int main() {
  lint a, b;
  lint s, t;

  scanf("%lld %lld", &a, &b);

  s = max(2ll, a - b);
  t = a + b;

  for (lint i = s; i <= t; i++)
    fox[i - s] = 999999;
  for (lint i = 3; i * i <= t; i += 2)
    prime[i] = true;
  prime[2] = true;

  for (lint i = 3; i * i <= t; i++) {
    if (prime[i]) {
      for (lint j = 3 * i; j <= t; j += 2 * i) {
        prime[j] = false;
      }
    }
  }

  for (lint p = 2; p * p <= t; p++) {
    if (prime[p]) {
      for (lint i = ((s + p - 1) / p) * p; i <= t; i += p) {
        if (i - s < 0)
          continue;
        lint tmp = i;
        int cnt = 0;
        while (tmp % p == 0) {
          tmp /= p;
          cnt++;
        }
        if (cnt > fox[i - s])
          fox[i - s] = -1;
        else
          fox[i - s] = cnt;
      }
    }
  }

  int ans = 0;
  for (int i = s; i <= t; i++) {
    if (~fox[i - s])
      ans++;
  }

  printf("%d\\n", ans);

  return (0);
}
Problem p01392 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

#define ll long long

using namespace std;

bool isprime[1000001];
int fact[1000001];
bool isfox[1000001];
int primes[78498];

int factorial(ll arg, int base) {
  int ret = 0;
  while (arg % base == 0) {
    arg /= base;
    ret++;
  }
  return ret;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  int cnt = 0;
  ll a, b;
  for (int i = 2; i < 1000001; i++) {
    if (!isprime[i]) {
      primes[cnt++] = i;
      for (int j = 2; i * j < 1000001; j++) {
        isprime[i * j] = true;
      }
    }
  }
  cin >> a >> b;
  ll len, bias;
  if (a - b < 2) {
    bias = 2;
  } else {
    bias = a - b;
  }
  len = a + b - bias + 1;

  fill((int *)fact, (int *)fact + 1000001, 1 << 29);

  for (int i = 0; i < 78498; i++) {
    for (int j = (primes[i] - bias % primes[i]) % primes[i]; j < len;
         j += primes[i]) {
      if (isfox[j])
        continue;
      int tmp = factorial(j + bias, primes[i]);
      if (tmp != 0) {
        if (fact[j] == 1 << 29 || fact[j] >= tmp) {
          fact[j] = tmp;
        } else {
          isfox[j] = true;
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < len; i++) {
    res += !isfox[i] ? 1 : 0;
  }
  cout << res << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

#define ll long long

using namespace std;

bool isprime[1000001];
int fact[1000001];
bool isfox[1000001];
int primes[78498];

int factorial(ll arg, int base) {
  int ret = 0;
  while (arg % base == 0) {
    arg /= base;
    ret++;
  }
  return ret;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  int cnt = 0;
  ll a, b;
  for (int i = 2; i < 1000001; i++) {
    if (!isprime[i]) {
      primes[cnt++] = i;
      for (int j = 2; i * j < 1000001; j++) {
        isprime[i * j] = true;
      }
    }
  }
  cin >> a >> b;
  ll len, bias;
  if (a - b < 2) {
    bias = 2;
  } else {
    bias = a - b;
  }
  len = a + b - bias + 1;

  fill((int *)fact, (int *)fact + 1000001, 1 << 29);

  for (int i = 0; (ll)primes[i] * primes[i] <= a + b; i++) {
    for (int j = (primes[i] - bias % primes[i]) % primes[i]; j < len;
         j += primes[i]) {
      if (isfox[j])
        continue;
      int tmp = factorial(j + bias, primes[i]);
      if (tmp != 0) {
        if (fact[j] == 1 << 29 || fact[j] >= tmp) {
          fact[j] = tmp;
        } else {
          isfox[j] = true;
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < len; i++) {
    res += !isfox[i] ? 1 : 0;
  }
  cout << res << endl;
}