alexjercan/bugnet huggingface dataset:
Problem p01168 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
int m(int a, int k) {
  if (!a)
    return 0;
  string s;
  while (a) {
    int tmp = a % k;
    if (tmp > 9)
      return -1;
    s += '0' + tmp;
    a /= k;
  }
  reverse(s.begin(), s.end());
  return stoll(s);
}
signed main() {
  int a, b, c;
  while (cin >> a >> b >> c, ~a) {
    bool f = 1;
    for (int i = 2; i <= 16; i++)
      f &= m(a, i) != b;
    int res = b;
    for (int j = a; j <= c; j++) {
      int tmp = -1;
      for (int i = 2; i <= 16; i++)
        if (m(j, i) >= res)
          if (tmp < 0 || m(j, i) < tmp)
            tmp = m(j, i);
      if (tmp < 0) {
        f = 1;
        break;
      }
      res = tmp;
    }
    cout << (f ? -1 : res) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
int m(int a, int k) {
  string s;
  while (a) {
    int tmp = a % k;
    if (tmp > 9)
      return -1;
    s += '0' + tmp;
    a /= k;
  }
  reverse(s.begin(), s.end());
  return stoll(s);
}
signed main() {
  int a, b, c;
  while (cin >> a >> b >> c, ~a) {
    bool f = 1;
    for (int i = 2; i <= 16; i++)
      f &= m(a, i) != b;
    int res = b;
    for (int j = a; j <= c; j++) {
      int tmp = -1;
      for (int i = 2; i <= 16; i++)
        if (m(j, i) >= res)
          if (tmp < 0 || m(j, i) < tmp)
            tmp = m(j, i);
      if (tmp < 0) {
        f = 1;
        break;
      }
      res = tmp;
    }
    cout << (f ? -1 : res) << endl;
  }
  return 0;
}
Problem p01171 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define MP make_pair

typedef long long LL;
typedef pair<int, int> PII;

const int NUM = 2000000;
int prime[NUM];
vector<int> primelist;

int gen() {
  for (int i = 0; i < NUM; i++) {
    prime[i] = 1;
  }
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= NUM; i++) {
    for (int j = 2 * i; j < NUM; j += i) {
      prime[j] = 0;
    }
  }

  for (int i = 0; i < NUM; i++) {
    if (prime[i] == 1)
      primelist.push_back(i);
  }
}

int main() {
  gen();

  while (true) {
    int a, b;
    int keya = 0, keyb = 0;

    scanf("%d %d", &a, &b);
    if (a == 0)
      break;

    int k;
    for (int i = 0; primelist[i] <= a; i++) {
      if (a % primelist[i] == 0) {
        keya -= primelist[i];
        k = primelist[i];
      }
    }
    keya += 2 * k;

    for (int i = 0; primelist[i] <= b; i++) {
      if (b % primelist[i] == 0) {
        keyb -= primelist[i];
        k = primelist[i];
      }
    }
    keyb += 2 * k;

    if (keya < keyb)
      printf("b\\n");
    else
      printf("a\\n");
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define MP make_pair

typedef long long LL;
typedef pair<int, int> PII;

const int NUM = 200000;
int prime[NUM];
vector<int> primelist;

int gen() {
  for (int i = 0; i < NUM; i++) {
    prime[i] = 1;
  }
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= NUM; i++) {
    for (int j = 2 * i; j < NUM; j += i) {
      prime[j] = 0;
    }
  }

  for (int i = 0; i < NUM; i++) {
    if (prime[i] == 1)
      primelist.push_back(i);
  }
}

int main() {
  gen();

  while (true) {
    int a, b;
    int keya = 0, keyb = 0;

    scanf("%d %d", &a, &b);
    if (a == 0)
      break;

    int k;
    for (int i = 0; primelist[i] <= a; i++) {
      if (a % primelist[i] == 0) {
        keya -= primelist[i];
        k = primelist[i];
      }
    }
    keya += 2 * k;

    for (int i = 0; primelist[i] <= b; i++) {
      if (b % primelist[i] == 0) {
        keyb -= primelist[i];
        k = primelist[i];
      }
    }
    keyb += 2 * k;

    if (keya < keyb)
      printf("b\\n");
    else
      printf("a\\n");
  }
}
Problem p01171 (C++) — buggy submission, verdict: Runtime Error

//============================================================================
// Name        : A.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool is_prime(int a) {
  for (int i = 2; i * i <= a; ++i) {
    if (a % i == 0)
      return false;
  }
  return true;
}

vector<int> ps;

int f(int a) {
  vector<ll> v;
  for (int p : ps) {
    if (a % p == 0)
      v.push_back(p);
  }
  if (v.size() == 0)
    return 0;
  ll ret = v.back();
  for (int i = 0; i < (int)v.size() - 1; i++) {
    ret -= v[i];
  }
  return ret;
}

int main() {
  for (int i = 2; i <= 2000000; i++) {
    if (is_prime(i))
      ps.push_back(i);
  }

  int n, m;
  while (cin >> n >> m, n + m) {
    if (f(n) > f(m)) {
      cout << "a" << endl;
    } else {
      cout << "b" << endl;
    }
  }
}

Error: -8

Fixed submission:

//============================================================================
// Name        : A.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool is_prime(int a) {
  for (int i = 2; i * i <= a; ++i) {
    if (a % i == 0)
      return false;
  }
  return true;
}

vector<int> ps;

int f(int a) {
  vector<ll> v;
  for (int p : ps) {
    if (a % p == 0)
      v.push_back(p);
  }
  if (v.size() == 0)
    return 0;
  ll ret = v.back();
  for (int i = 0; i < (int)v.size() - 1; i++) {
    ret -= v[i];
  }
  return ret;
}

int main() {
  for (int i = 0; i <= 200000; i++) {
    if (is_prime(i))
      ps.push_back(i);
  }

  int n, m;
  while (cin >> n >> m, n + m) {
    if (f(n) > f(m)) {
      cout << "a" << endl;
    } else {
      cout << "b" << endl;
    }
  }
}
Problem p01171 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX 1000100

bool p1[MAX], p2[MAX];
int a, b;
int A, B;

void makeA(int n) {
  for (int i = 2; i <= n; i++) {
    while (true) {
      if (n % i == 0) {
        p1[i] = true;
        n /= i;
        A = max(A, i);
      } else
        break;
    }
  }
}

void makeB(int n) {
  for (int i = 2; i <= n; i++) {
    while (true) {
      if (n % i == 0) {
        p2[i] = true;
        n /= i;
        B = max(B, i);
      } else
        break;
    }
  }
}

void init() {
  memset(p1, false, sizeof(p1));
  memset(p2, false, sizeof(p2));
  A = 0, B = 0;
}

int main() {
  while (cin >> a >> b) {
    if (a == 0 && b == 0)
      break;
    init();
    makeA(a);
    makeB(b);

    int m = A;
    for (int i = 0; i < m; i++) {
      if (p1[i])
        A -= i;
    }
    m = B;
    for (int i = 0; i < m; i++) {
      if (p2[i])
        B -= i;
    }

    if (A > B)
      cout << 'a' << endl;
    else
      cout << 'b' << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define MAX 100001

bool p1[MAX], p2[MAX];
int a, b;
int A, B;

void makeA(int n) {
  for (int i = 2; i <= n; i++) {
    if (n % i == 0) {
      p1[i] = true;
      n /= i;
      A = max(A, i);
    }
  }
}

void makeB(int n) {
  for (int i = 2; i <= n; i++) {
    if (n % i == 0) {
      p2[i] = true;
      n /= i;
      B = max(B, i);
    }
  }
}

void init() {
  memset(p1, false, sizeof(p1));
  memset(p2, false, sizeof(p2));
  A = 0, B = 0;
}

int main() {
  while (cin >> a >> b) {
    if (a == 0 && b == 0)
      break;
    init();
    makeA(a);
    makeB(b);

    for (int i = 0; i <= A; i++) {
      if (p1[i])
        A -= i;
    }
    for (int i = 0; i <= B; i++) {
      if (p2[i])
        B -= i;
    }

    // cout<<A << endl << B << endl;

    if (A > B)
      cout << 'a' << endl;
    else
      cout << 'b' << endl;
  }
  return 0;
}
Problem p01171 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

bool comp(const int &v1, const int &v2) { return v1 > v2; }

int main() {
  bool pr[1000001];
  int s, t, a[1001], b[1001], p, q;

  fill(pr, pr + 1000001, true);
  pr[0] = pr[1] = false;
  for (int i = 2; i <= 1000000; i++) {
    if (pr[i]) {
      for (int j = 2 * i; j <= 1000000; j += i) {
        pr[j] = false;
      }
    }
  }

  while (1) {
    cin >> s >> t;
    if (s == 0 && t == 0) {
      break;
    }
    p = q = 0;

    for (int i = 2; i <= s; i++) {
      if (pr[i] && s % i == 0) {
        a[p++] = i;
      }
    }
    for (int i = 2; i <= t; i++) {
      if (pr[i] && t % i == 0) {
        b[q++] = i;
      }
    }
    sort(a, a + p, comp);
    sort(b, b + q, comp);
    s = a[0];
    t = b[0];
    for (int i = 1; i < p; i++) {
      s -= a[i];
    }
    for (int i = 1; i < q; i++) {
      t -= b[i];
    }

    if (s > t) {
      cout << "a" << endl;
    } else {
      cout << "b" << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int s, t, u, v, p = 0, prime[80000], a, b;

  prime[p++] = 2;
  for (int i = 3; i <= 1000000; i += 2) {
    bool f = true;
    for (int j = 3; j * j <= i; j += 2) {
      if (i % j == 0) {
        f = false;
        break;
      }
    }
    if (f) {
      prime[p++] = i;
    }
  }

  while (1) {
    cin >> s >> t;
    if (s == 0 && t == 0) {
      break;
    }
    u = v = 0;
    a = b = -1;
    for (int i = 0; s > prime[i]; i++) {
      if (s % prime[i] == 0) {
        u += prime[i];
        a = i;
      }
    }
    if (a > 0) {
      u = 2 * prime[a] - u;
    }

    for (int i = 0; t > prime[i]; i++) {
      if (t % prime[i] == 0) {
        v += prime[i];
        b = i;
      }
    }
    if (b > 0) {
      v = 2 * prime[b] - v;
    }

    if (u > v) {
      cout << "a" << endl;
    } else {
      cout << "b" << endl;
    }
  }

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

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

int p[1000001];
vector<int> plist;

int f(int a) {
  if (p[a] == 0)
    return a;
  vector<int> p;
  int sum = 0;
  for (int i = 0; i < plist.size(); ++i) {
    if (a % plist[i] == 0) {
      p.push_back(plist[i]);
      while (a % plist[i] == 0)
        a /= plist[i];
      sum += plist[i];
    }
    if (a == 1)
      break;
  }

  sum -= p[p.size() - 1];
  return p[p.size() - 1] - sum;
}

int main() {
  memset(p, 0, sizeof(p));
  p[0] = p[1] = 1;
  for (int i = 4; i <= 1000000; i += 2)
    p[i] = 1;
  for (int i = 3; i * i <= 1000000; i += 2)
    if (p[i] == 0)
      for (int j = 2; i * j <= 1000000; j++)
        p[i * j] = 1;
  plist.clear();

  for (int i = 0; i <= 1000000; ++i)
    if (p[i] == 0)
      plist.push_back(i);

  int a, b;
  while (cin >> a >> b, a | b) {
    int fa = f(a), fb = f(b);
    if (fa > fb) {
      cout << "a" << endl;
    } else {
      cout << "b" << endl;
    }
  }
}

Error: 0

Fixed submission:

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

int p[10001];
vector<int> plist;

int f(int a) {
  vector<int> p;
  int sum = 0;
  for (int i = 0; i < plist.size(); ++i) {
    if (a % plist[i] == 0) {
      p.push_back(plist[i]);
      while (a % plist[i] == 0)
        a /= plist[i];
      sum += plist[i];
    }
  }

  sum -= p[p.size() - 1];
  return p[p.size() - 1] - sum;
}

int main() {
  memset(p, 0, sizeof(p));
  p[0] = p[1] = 1;
  for (int i = 4; i <= 10000; i += 2)
    p[i] = 1;
  for (int i = 3; i * i <= 10000; i += 2)
    if (p[i] == 0)
      for (int j = 2; i * j <= 10000; j++)
        p[i * j] = 1;
  plist.clear();
  for (int i = 0; i <= 10000; ++i)
    if (p[i] == 0)
      plist.push_back(i);

  int a, b;
  while (cin >> a >> b, a | b) {
    int fa = f(a), fb = f(b);
    if (fa > fb) {
      cout << "a" << endl;
    } else {
      cout << "b" << endl;
    }
  }
}
Problem p01171 (C++) — buggy submission, verdict: Runtime Error

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

bool inp[1000001];

int main() {
  memset(inp, false, sizeof(inp));
  inp[0] = inp[1] = true;
  for (int i = 2; i * i <= 1000000; ++i)
    if (!inp[i])
      for (int j = 2; i * j <= 1000000; ++j)
        inp[i * j] = true;

  int a, b;
  while (cin >> a >> b, a | b) {
    vector<int> af, bf;
    for (int i = 1; i <= max(a, b); ++i) {
      if (inp[i])
        continue;
      if (a % i == 0)
        af.push_back(i);
      if (b % i == 0)
        bf.push_back(i);
    }

    int maxaf = af.back();
    af.pop_back();
    int maxbf = bf.back();
    bf.pop_back();

    for (int i = 0; i < af.size(); ++i)
      maxaf -= af[i];
    for (int i = 0; i < bf.size(); ++i)
      maxbf -= bf[i];

    if (maxaf > maxbf)
      cout << "a" << endl;
    else
      cout << "b" << endl;
  }
}

Error: 0

Fixed submission:

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

bool inp[10001];

int main() {
  memset(inp, false, sizeof(inp));
  inp[0] = inp[1] = true;
  for (int i = 2; i * i <= 10000; ++i)
    if (!inp[i])
      for (int j = 2; i * j <= 10000; ++j)
        inp[i * j] = true;

  int a, b;
  while (cin >> a >> b, a | b) {
    vector<int> af, bf;
    for (int i = 1; i <= max(a, b); ++i) {
      if (inp[i])
        continue;
      if (a % i == 0)
        af.push_back(i);
      if (b % i == 0)
        bf.push_back(i);
    }

    // for(int i=0; i<af.size(); ++i) cout<<af[i]<<" ";
    // cout<<endl;

    // for(int i=0; i<bf.size(); ++i) cout<<bf[i]<<" ";
    // cout<<endl;

    int maxaf = af.back();
    af.pop_back();
    int maxbf = bf.back();
    bf.pop_back();

    for (int i = 0; i < af.size(); ++i)
      maxaf -= af[i];
    for (int i = 0; i < bf.size(); ++i)
      maxbf -= bf[i];

    if (maxaf > maxbf)
      cout << "a" << endl;
    else
      cout << "b" << endl;
  }
}
Problem p01171 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, a) FOR(i, 0, a)
#define TRACE(x) // cout << #x << " " << x << endl
#define _ << " _ " <<

using namespace std;

#define task "a"

const int MAXN = 1000010;

int a, b;
int sito[MAXN];

int main() {

  //  freopen(task ".in", "r", stdin);
  //  freopen(task ".out", "w", stdout);

  FOR(i, 2, MAXN) {
    if (sito[i] != 0)
      continue;
    for (int j = i; j < MAXN; j += i) {
      sito[j] = i;
    }
  }

  while (1 == 1) {
    scanf("%d%d", &a, &b);
    if (a == 0 && b == 0)
      break;
    int sumA = sito[a];
    int sumB = sito[b];
    while (sito[a] == sumA)
      a /= sito[a];
    while (sito[b] == sumB)
      b /= sito[b];

    TRACE(sumA _ sumB);

    while (a != 1) {
      int pom = sito[a];
      sumA -= pom;
      while (sito[a] == pom)
        a /= sito[a];
      TRACE(pom);
    }
    while (b != 1) {
      int pom = sito[b];
      sumB -= pom;
      while (sito[b] == pom)
        b /= sito[b];
      TRACE(pom);
    }

    if (sumA > sumB)
      printf("a\\n");
    else
      printf("b\\n");
  }

  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, a) FOR(i, 0, a)
#define TRACE(x) cout << #x << " " << x << endl
#define _ << " _ " <<

using namespace std;

#define task "a"

const int MAXN = 1000010;

#define znj znj2

int a, b;
int sito[MAXN];

int main() {

  freopen(task ".in", "r", stdin);
  freopen(task ".out", "w", stdout);

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

  FOR(i, 2, MAXN) {
    if (sito[i] != 0)
      continue;
    for (int j = i; j < MAXN; j += i) {
      sito[j] = i;
    }
  }

  int sumA = sito[a];
  int sumB = sito[b];
  a /= sito[a];
  b /= sito[b];

  while (a != 1) {
    sumA -= sito[a];
    a /= sito[a];
  }
  while (b != 1) {
    sumB -= sito[b];
    b /= sito[b];
  }

  if (sumA > sumB)
    printf("a\\n");
  else
    printf("b\\n");

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

#include <cstdio>
using namespace std;

#define MAXNUM 1000001
bool prime[MAXNUM];

void eratosthenes() {
  prime[0] = prime[1] = false;

  for (int i = 2; i < MAXNUM; i++) {
    prime[i] = true;
  }

  for (int i = 2; i * i < MAXNUM; i++) {
    if (prime[i]) {
      for (int j = i * i; j < MAXNUM; j += i) {
        prime[j] = false;
      }
    }
  }
}

int getkey(int a) {
  int t;
  for (int i = a; i >= 2; i--) {
    if (a % i != 0)
      continue;
    if (prime[i]) {
      t = i;
      break;
    }
  }
  int ret = t;
  for (int i = t - 1; i >= 2; i--) {
    if (a % i != 0)
      continue;
    if (prime[i])
      ret -= i;
  }

  return ret;
}

int main() {
  eratosthenes();
  int a, b;
  while (scanf("%d%d", &a, &b), (a || b)) {
    if (getkey(a) > getkey(b))
      puts("a");
    else
      puts("b");
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

#define MAXNUM 1000001
bool prime[MAXNUM];

void eratosthenes() {
  prime[0] = prime[1] = false;

  for (int i = 2; i < MAXNUM; i++) {
    prime[i] = true;
  }

  for (int i = 2; i * i < MAXNUM; i++) {
    if (prime[i]) {
      for (int j = i * i; j < MAXNUM; j += i) {
        prime[j] = false;
      }
    }
  }
}

int getkey(int a) {
  int t;
  for (int i = a; i >= 2; i--) {
    if (a % i != 0)
      continue;
    if (prime[i]) {
      t = i;
      break;
    }
  }
  int ret = t;
  for (int i = t - 1; i >= 2; i--) {
    if (a % i != 0)
      continue;
    if (prime[i])
      ret -= i;
  }

  return ret;
}

int main() {
  eratosthenes();
  int a, b;
  while (scanf("%d%d", &a, &b)) {
    if (getkey(a) > getkey(b))
      puts("a");
    else
      puts("b");
  }
}
Problem p01171 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef vector<int> vi;
const int lim = 1000001;

vi prime_fact(int x, const vi &table) {
  vi res;
  while (x > 1) {
    res.push_back(table[x]);
    x /= table[x];
  }
  sort(all(res));
  res.erase(unique(all(res)), res.end());
  return res;
}

int main() {
  vi table(lim, 1);
  for (int i = 2; i <= lim; i++) {
    if (table[i] == 1) {
      for (int j = i; j <= lim; j += i)
        table[j] = i;
    }
  }

  int a, b;
  while (cin >> a >> b, a) {
    vi va = prime_fact(a, table), vb = prime_fact(b, table);
    a = 2 * va.back() - accumulate(all(va), 0);
    b = 2 * vb.back() - accumulate(all(vb), 0);
    cout << (a > b ? "a" : "b") << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef vector<int> vi;
const int lim = 1000001;

vi prime_fact(int x, const vi &table) {
  vi res;
  while (x > 1) {
    res.push_back(table[x]);
    x /= table[x];
  }
  sort(all(res));
  res.erase(unique(all(res)), res.end());
  return res;
}

int main() {
  vi table(lim, 1);
  for (int i = 2; i * i <= lim; i++) {
    if (table[i] == 1) {
      for (int j = i; j <= lim; j += i)
        table[j] = i;
    }
  }

  int a, b;
  while (cin >> a >> b, a) {
    vi va = prime_fact(a, table), vb = prime_fact(b, table);
    a = 2 * va.back() - accumulate(all(va), 0);
    b = 2 * vb.back() - accumulate(all(vb), 0);
    cout << (a > b ? "a" : "b") << endl;
  }
}
Problem p01171 (C++) — buggy submission, verdict: Runtime Error

#include <bitset>
#include <stdio.h>
#include <vector>
const int N = 1000000;
int main() {
  std::bitset<N> p;
  std::vector<int> v, A, B;
  int i, j, a, b;
  for (i = 2; i < N; ++i)
    if (!p[i])
      for (v.push_back(i), j = i * 2; j < N; j += i)
        p[j] = 1;
  while (scanf("%d%d", &a, &b), a) {
    A.clear(), B.clear();
    for (i = 0; i < v.size(); ++i) {
      if (a % v[i] == 0)
        A.push_back(v[i]);
      if (b % v[i] == 0)
        B.push_back(v[i]);
    }
    for (a = A.back(), i = 0; i < A.size() - 1; ++i)
      a -= A[i];
    for (b = B.back(), i = 0; i < B.size() - 1; ++i)
      b -= B[i];
    puts(a > b ? "a" : "b");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bitset>
#include <stdio.h>
#include <vector>
const int N = 100000;
int main() {
  std::bitset<N> p;
  std::vector<int> v, A, B;
  int i, j, a, b;
  for (i = 2; i < N; ++i)
    if (!p[i])
      for (v.push_back(i), j = i * 2; j < N; j += i)
        p[j] = 1;
  while (scanf("%d%d", &a, &b), a) {
    A.clear(), B.clear();
    for (i = 0; i < v.size(); ++i) {
      if (a % v[i] == 0)
        A.push_back(v[i]);
      if (b % v[i] == 0)
        B.push_back(v[i]);
    }
    for (a = A.back(), i = 0; i < A.size() - 1; ++i)
      a -= A[i];
    for (b = B.back(), i = 0; i < B.size() - 1; ++i)
      b -= B[i];
    puts(a > b ? "a" : "b");
  }
  return 0;
}
Problem p01171 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll prime[1000001];
ll length = 0;
void insert(ll p) {
  prime[length] = p;
  length++;
  return;
}
int main() {
  insert(2);
  for (ll i = 3; i < 1000000; i += 2) {
    for (ll j = 0; j < length; j++)
      if (i % prime[j] == 0)
        goto cont;
      else if (prime[j] > sqrt(i))
        break;
    insert(i);
  cont:;
  }
  ll a, b;
  while (cin >> a >> b) {
    if (!a && !b)
      return 0;
    ll am, bm, ac = 0, bc = 0;
    int i = 0;
    while (prime[i] <= a) {
      if (a % prime[i] == 0) {
        am = prime[i];
        ac += prime[i];
        while (a % prime[i] == 0)
          a /= prime[i];
        if (a == 1)
          break;
      }
      i++;
    }
    ac -= am;
    am -= ac;
    i = 0;
    while (prime[i] <= b) {
      if (b % prime[i] == 0) {
        bm = prime[i];
        bc += prime[i];
        while (b % prime[i] == 0)
          b /= prime[i];
        if (b == 1)
          break;
      }
      i++;
    }
    bc -= bm;
    bm -= bc;
    if (am > bm)
      cout << "a\\n";
    else
      cout << "b\\n";
  }
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll prime[1000001];
ll length = 0;
void insert(ll p) {
  prime[length] = p;
  length++;
  return;
}
int main() {
  insert(2);
  for (ll i = 3; i < 1000000; i += 2) {
    for (ll j = 0; j < length; j++)
      if (i % prime[j] == 0)
        goto cont;
      else if (prime[j] > sqrt(i))
        break;
    insert(i);
  cont:;
  }
  ll a, b;
  while (cin >> a >> b) {
    if (!a && !b)
      return 0;
    ll am, bm, ac = 0, bc = 0;
    int i = 0;
    while (prime[i] <= a) {
      if (a % prime[i] == 0) {
        am = prime[i];
        ac += prime[i];
      }
      i++;
    }
    ac -= am;
    am -= ac;
    i = 0;
    while (prime[i] <= b) {
      if (b % prime[i] == 0) {
        bm = prime[i];
        bc += prime[i];
      }
      i++;
    }
    bc -= bm;
    bm -= bc;
    if (am > bm)
      cout << "a\\n";
    else
      cout << "b\\n";
  }
}