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

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

#define loop(n, i) for (int i = 0; i < n; i++)
#define loop_from_to(from, to, i) for (int i = from; i <= to; i++)
#define repeat(n) for (int i__ = 0; i__ < n; i__++)
#define multi_cin(n, array)                                                    \\
  loop(n, i) { cin >> array[i]; }
#define assign_if_smaller(var, val)                                            \\
  if (var > val)                                                               \\
    var = val;
#define assign_if_larger(var, val)                                             \\
  if (var < val)                                                               \\
    var = val;
#define each(itr, c)                                                           \\
  for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
#define r_each(itr, c)                                                         \\
  for (__typeof((c).rbegin()) itr = (c).rbegin(); itr != (c).rend(); itr++)

using namespace std;

int main(int argc, char const *argv[]) {
  while (1) {
    int n, a, b;
    cin >> n >> a >> b;
    if (!n && !a && !b)
      break;

    bool c[n];
    fill(c, c + n, false);
    if (a - 1 < n)
      c[a - 1] = true;
    if (b - 1 < n)
      c[b - 1] = true;

    int count = 0;
    loop(n, i) {
      if (!c[i])
        count++;
      else {
        if (i + a < n)
          c[i + a] = true;
        if (i + b < n)
          c[i + b] = true;
      }
    }
    cout << count << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

#define loop(n, i) for (int i = 0; i < n; i++)
#define loop_from_to(from, to, i) for (int i = from; i <= to; i++)
#define repeat(n) for (int i__ = 0; i__ < n; i__++)
#define multi_cin(n, array)                                                    \\
  loop(n, i) { cin >> array[i]; }
#define assign_if_smaller(var, val)                                            \\
  if (var > val)                                                               \\
    var = val;
#define assign_if_larger(var, val)                                             \\
  if (var < val)                                                               \\
    var = val;
#define each(itr, c)                                                           \\
  for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
#define r_each(itr, c)                                                         \\
  for (__typeof((c).rbegin()) itr = (c).rbegin(); itr != (c).rend(); itr++)

using namespace std;

int main(int argc, char const *argv[]) {
  while (1) {
    int n, a, b;
    cin >> n >> a >> b;
    if (!n && !a && !b)
      break;

    bool c[n];
    fill(c, c + n, false);
    c[a - 1] = true;
    c[b - 1] = true;

    int count = 0;
    loop(n, i) {
      if (!c[i])
        count++;
      else {
        if (i + a < n)
          c[i + a] = true;
        if (i + b < n)
          c[i + b] = true;
      }
    }
    cout << count << endl;
  }

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

#include <algorithm>
#include <iostream>

using namespace std;

bool ok(int n, int a, int b) {
  if (a < b)
    swap(a, b);
  for (int i = 0; i <= n; i += a) {
    if ((n - i) % b == 0)
      return true;
  }
  return false;
}

int main() {
  int n, a, b;

  while (cin >> n >> a >> b, n | a | b) {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (ok(i, a, b))
        continue;
      ans++;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

bool ok(int n, int a, int b) {
  for (int i = 0; i <= n; i += a) {
    if ((n - i) % b == 0)
      return true;
  }
  return false;
}

int main() {
  int n, a, b;

  while (cin >> n >> a >> b, n | a | b) {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (ok(i, a, b))
        continue;
      ans++;
    }
    cout << ans << endl;
  }
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n, a, b;

int gcd(int a, int b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}

int main() {
  while (cin >> n >> a >> b && n) {
    set<int> s;
    int d = gcd(a, b), m = a * b / d;
    for (int i = 0; i <= m / a; i++)
      for (int j = 0; j <= m / b; j++) {
        if (i * a + j * b && i * a + j * b <= m)
          s.insert(i * a + j * b);
      }
    if (n >= m)
      cout << n - n / d + m / d - s.size() << endl;
    else {
      set<int>::iterator ite;
      int ans = n;
      for (ite = s.begin(); ite != s.end(); ite++)
        if (*ite <= n)
          ans--;
      cout << ans << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int a, b, m, n, p;
  while (cin >> m >> a >> b, m) {
    n = 0;
    for (int h = 1; h <= m; h++) {
      p = 0;
      for (int i = 0; i <= h / a; i++) {
        if (p)
          break;
        for (int j = 0; j <= h / b; j++) {
          if (h == a * i + b * j) {
            p = 1;
            break;
          }
        }
      }
      if (p == 0)
        n++;
    }
    cout << n << endl;
  }
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>

using namespace std;

char c[1000001] = {0};

int main() {
  for (;;) {
    int n, a, b;

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

    memset(c, 0, sizeof(c));
    c[0] = 1;
    for (int i = 0; i <= n; ++i) {
      if (c[i] == 1) {
        if (i + a <= n)
          c[i + a] = 1;
        if (i + b <= n)
          c[i + b] = 1;
      }
    }

    int t = 0;
    for (int i = 1; i <= n; ++i)
      if (c[i] == 0)
        ++t;

    printf("%d\\n", t);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

using namespace std;

char c[1000001] = {0};

int main() {
  for (;;) {
    int n, a, b;

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

    memset(c, 0, sizeof(c));
    for (int i = 0; a * i <= n; ++i) {
      for (int j = 0; a * i + b * j <= n; ++j) {
        c[a * i + b * j] = 1;
        // printf("  %d, %d\\n", i, j);
      }
    }

    int t = 0;
    for (int i = 1; i <= n; ++i)
      if (c[i] == 0)
        ++t;

    printf("%d\\n", t);
  }

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

// 05
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  for (int n, a, b; cin >> n >> a >> b, n | a | b;) {
    static bool ap[1000001];
    fill(ap, ap + 1000001, false);
    ap[0] = true;
    for (int i = a; i <= n; i++) {
      ap[i] = ap[i - a];
    }
    for (int i = b; i <= n; i++) {
      ap[i] |= ap[i - b];
    }
    cout << count(ap + 1, ap + 1 + n, false) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

// 05
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  for (int n, a, b; cin >> n >> a >> b, n | a | b;) {
    static bool ap[1000001];
    fill(ap, ap + 1000001, false);
    for (int i = 0; i * a <= n; i++) {
      for (int j = 0; j * b + i * a <= n; j++) {
        ap[i * a + j * b] = true;
      }
    }
    cout << count(ap + 1, ap + 1 + n, false) << endl;
  }
  return 0;
}
Problem p00687 (C++) — buggy submission, verdict: Runtime Error

// AOJ 1105
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

typedef vector<int> Seq;

const int NMAX = 2000100;

int solve(int a, int b, int n) {
  bool countable[NMAX];
  REP(i, n + 1) { countable[i] = false; }
  countable[0] = true;

  int unables = 0;
  REP(i, n + 1) {
    if (countable[i]) {
      countable[i + a] = true;
      countable[i + b] = true;
    } else {
      unables++;
    }
  }
  return unables;
}

int main() {
  int a, b, n;
  while (cin >> n >> a >> b and n + a + b) {
    cout << solve(a, b, n) << endl;
  }
}

Error: 0

Fixed submission:

// AOJ 1105
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

typedef vector<int> Seq;

const int NMAX = 1000100;

int solve(int a, int b, int n) {
  bool countable[NMAX];
  REP(i, n + 1) { countable[i] = false; }
  countable[0] = true;

  int unables = 0;
  REP(i, n + 1) {
    if (countable[i]) {
      countable[i + a] = true;
      countable[i + b] = true;
    } else {
      unables++;
    }
  }
  return unables;
}

int main() {
  int a, b, n;
  while (cin >> n >> a >> b and n + a + b) {
    cout << solve(a, b, n) << endl;
  }
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, a, b;
bool nr[1000003];

int main() {
  cin >> n >> a >> b;
  while (n + a + b > 0) {
    fill(nr + 1, nr + n + 1, 1);
    for (int i = 0; i <= n; i++) {
      if (!nr[i]) {
        if (i + a <= n)
          nr[i + a] = 0;
        if (i + b <= n)
          nr[i + b] = 0;
      }
    }
    int ans = 0;
    for (int i = 0; i < n + 1; i++) {
      ans += nr[i];
    }
    cout << ans << endl;
    cin >> n >> a >> b;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int n, a, b;
bool ifrepr[1000000];

int main() {
  cin >> n >> a >> b;
  while (n + a + b > 0) {
    fill(ifrepr, ifrepr + n, 1);
    for (int i = 0; i * a <= n; i++) {
      for (int j = 0; i * a + j * b <= n; j++) {
        ifrepr[i * a + j * b] = 0;
      }
    }
    int ans = 0;
    for (int i = 0; i < n + 1; i++) {
      ans += ifrepr[i];
    }
    cout << ans << endl;
    cin >> n >> a >> b;
  }
  return 0;
}
Problem p00687 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
const int MAX = 2000002;
bool c[MAX + 1];

int main() {
  int n, a, b;

  while (cin >> n >> a >> b, n + a + b) {
    int cnt = 0;
    for (int i = 0; i <= n; i++)
      c[i] = false;
    c[0] = true;

    for (int i = 0; i <= n; i++) {
      if (c[i] && (i + a <= n || i + b <= n)) {
        c[i + a] = true;
        c[i + b] = true;
      }
    }
    for (int i = 1; i <= n; i++)
      if (!c[i])
        cnt++;

    cout << cnt << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
const int MAX = 1000002;

int main() {
  bool c[MAX + 1];
  int n, a, b;

  while (cin >> n >> a >> b, n + a + b) {
    int cnt = 0;
    fill(c, c + MAX, false);
    c[0] = true;

    for (int i = 0; i <= n; i++) {
      if (c[i] && (i + a <= n || i + b <= n)) {
        c[i + a] = true;
        c[i + b] = true;
      }
    }
    for (int i = 1; i <= n; i++)
      if (!c[i])
        cnt++;

    cout << cnt << endl;
  }

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

#include <algorithm>
#include <iostream>

using namespace std;

int main() {

  int n, a, b, count = 0, i, j;

  cin >> n >> a >> b;
  while (n != 0) {
    count = n;
    if (a < b)
      swap(a, b);
    int ar[1000010] = {};
    ar[a] = 1;
    ar[b] = 1;
    for (i = 1; i <= n; i++) {
      if (i - a > 0)
        if (ar[i - a] == 1)
          ar[i] = 1;
      if (i - b > 0)
        if (ar[i - b] == 1)
          ar[i] = 1;
      count -= ar[i];
    }
    cout << count << endl;
    cin >> n >> a >> b;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {

  int n, a, b, count = 0, i, j;
  cin >> n >> a >> b;
  while (n != 0) {
    count = 0;
    if (a < b)
      swap(a, b);
    for (i = 1; i <= n; i++) {
      int flag = 0;
      for (j = 0; j <= i / a; j++) {
        if ((i - a * j) % b == 0) {
          flag = 1;
        }
      }
      if (flag == 0)
        count++;
    }

    cout << count << endl;
    cin >> n >> a >> b;
  }

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

#include <iostream>
#include <string.h>
#include <vector>

using namespace std;
static const int SIZE = 1000001;
int dp[SIZE];

void solve() {
  long long int n, a, b;
  while (cin >> n >> a >> b, n || a || b) {
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    for (int i = 0; i <= n; ++i) {
      if (dp[i] == 1) {
        if (i + a <= n) {
          dp[i + a] = 1;
        }
        if (i + b <= n) {
          dp[i + b] = 1;
        }
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (dp[i] == 0) {
        ++ans;
      }
    }
    cout << ans << endl;
  }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

void solve() {
  int n, a, b;
  while (cin >> n >> a >> b, n || a || b) {
    vector<int> canExpress(n + 1);
    for (int i = 0; i <= n; i += a) {
      for (int j = 0; i + j <= n; j += b) {
        canExpress[i + j]++;
      }
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      if (canExpress[i] > 0) {
        ++cnt;
      }
    }
    cout << n - cnt << endl;
  }
}

int main() {
  solve();
  return (0);
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
  int n, a, b;
  bool able[10000000];
  while (cin >> n >> a >> b) {
    memset(able, 0, sizeof(able));
    if (n == 0)
      break;
    if (a > b)
      swap(a, b);
    able[0] = true;
    for (int i = 0; i + a <= n; i++) {
      if (able[i])
        able[i + a] = true;
    }
    for (int i = 0; i + b <= n; i++) {
      if (able[i])
        able[i + b] = true;
    }
    int count = n;
    for (int i = 1; i <= n; i++) {
      if (able[i])
        count--;
    }
    cout << count << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
  int n, a, b;
  while (cin >> n >> a >> b) {
    if (n == 0)
      break;
    set<int> able;
    if (a > b)
      swap(a, b);
    for (int i = 0; i <= n / a; i++) {
      for (int j = 0; j <= n / b; j++) {
        if (i == 0 && j == 0)
          continue;
        int x = a * i + b * j;
        if (x > n)
          break;
        able.insert(x);
      }
    }
    cout << n - able.size() << endl;
  }
  return 0;
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

typedef long long int lli;

template <typename Integer> Integer GCD(Integer a, Integer b) {
  if (!b)
    return a;
  else
    return GCD(b, a % b);
}

template <typename Integer>
inline pair<Integer, pair<Integer, Integer>> ExtendedGCD(Integer a, Integer b) {
  pair<Integer, pair<Integer, Integer>> ret, tmp;
  if (b == 0)
    return make_pair(a, make_pair(1, 0));
  tmp = ExtendedGCD(b, a % b);
  ret.first = tmp.first;
  ret.second.first = tmp.second.second;
  ret.second.second = tmp.second.first - (a / b) * tmp.second.second;
  return ret;
}

template <typename Integer>
inline bool SolveModEquation(Integer a, Integer b, Integer n) {
  pair<Integer, pair<Integer, Integer>> t;
  t = ExtendedGCD(a, n);
  if (b % t.first == 0) {
    Integer ini_x = (t.second.first * (b / t.first)) % n;
    for (int i = 0; i < t.first; ++i) {
      Integer I = (ini_x + i * (n / t.first)) % n;
      if (I < 0)
        I += n;
      Integer J = (b - a * I) / n;
      if (I >= 0 && J >= 0 && a * I + n * J == b)
        return true;
    }
  }
  return false;
}

int main() {
  while (true) {
    int ableCount = 0;
    lli n, a, b;
    cin >> n >> a >> b;
    if (n == 0 && a == 0 && b == 0)
      break;
    for (lli k = 1; k <= n; k++) {
      if (SolveModEquation(a, k, b))
        ++ableCount;
    }
    cout << n - ableCount << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

typedef long long int lli;

lli gcd(lli a, lli b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

lli lcm(lli a, lli b) {
  if (a < b)
    swap(a, b);
  lli g = gcd(a, b);
  return b * (a / g);
}

int main() {
  while (true) {
    int ableCount = 0;
    int n, a, b;
    cin >> n >> a >> b;
    if (n == 0 && a == 0 && b == 0)
      break;
    for (int k = 1; k <= n; k++) {
      for (int j = 0; a * j <= k; ++j) {
        if ((k - a * j) % b == 0) {
          ++ableCount;
          break;
        }
      }
    }
    cout << n - ableCount << endl;
  }
  return 0;
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
 * AOJ 1105 Unable Count
 * n, a, b <= 1,000,000
 */

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

using namespace std;

#define MAX_N 1000001

int n, a, b;
bool pos[MAX_N];
void init() {
  memset(pos, 0, sizeof(pos));
  for (int i = 0; i <= n; i += a) {
    for (int j = i; j <= n; j += b) {
      if (pos[j])
        break;
      pos[j] = true;
    }
  }
}

int main() {
  while (cin >> n >> a >> b) {
    if (n == 0 && a == 0 && b == 0)
      break;
    init();
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (!pos[i]) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

/*
 * AOJ 1105 Unable Count
 * n, a, b <= 1,000,000
 */

#include <cstring>
#include <iostream>

using namespace std;

#define MAX_N 1000001

int n, a, b;
bool pos[MAX_N];
void init() {
  memset(pos, 0, sizeof(pos));
  for (int i = 0; i <= n; i += a) {
    for (int j = i; j <= n; j += b) {
      pos[j] = true;
    }
  }
}

int main() {
  while (cin >> n >> a >> b) {
    if (n == 0 && a == 0 && b == 0)
      break;
    if (a > b)
      swap(a, b);
    init();
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (!pos[i]) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long ll;
#define MAX 1000001
using namespace std;
int main() {
  int n, a, b;
  while (cin >> n >> a >> b) {
    if (n == 0 && a == 0 && b == 0)
      break;
    bool dp[MAX];
    memset(dp, false, sizeof(dp));
    dp[0] = true;

    for (int i = 0; i <= n; i++) {
      if (dp[i]) {
        if (i + a <= n)
          dp[i + a] = true;
        if (i + b <= n)
          dp[i + b] = true;
      }
    }

    int cnt = 0;

    for (int i = 0; i <= n; i++)
      if (!dp[i])
        cnt++;
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
  int n, a, b;
  while (cin >> n >> a >> b) {
    if (n == 0 && a == 0 && b == 0)
      break;
    int cnt = n;

    for (int t = 1; t <= n; t++) {
      bool flag = 0;
      for (int i = 0; a * i + 1 <= n; i++) {
        for (int j = 0; a * i + b * j + 1 <= n; j++) {
          if (a * i + b * j == t) {
            cnt--;
            flag = 1;
            break;
          }
        }
        if (flag == 1)
          break;
      }
    }

    cout << cnt - 1 << endl;
  }
  return 0;
}
Problem p00687 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <utility>
using namespace std;

int main() {
  while (1) {
    long n, a, b;
    scanf(" %ld %ld %ld", &n, &a, &b);
    if (n == 0)
      break;

    if (a > b)
      swap(a, b);

    long ans = 0;
    bool x[1000001];

    for (long i = 1; i <= n; ++i)
      x[i] = false;
    x[0] = true;

    // 作れない数を探す
    for (long i = 0; i <= n; ++i) {
      if (x[i]) {
        if (i + a <= n)
          x[i + a] = true;
        if (i + b <= n)
          x[i + b] = true;
      }
    }

    for (long i = 1; i <= n; ++i)
      if (!x[i])
        ++ans;

    printf("%ld\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <utility>
using namespace std;

int main() {
  while (1) {
    long n, a, b;
    scanf(" %ld %ld %ld", &n, &a, &b);
    if (n == 0)
      break;

    if (a > b)
      swap(a, b);

    long ans = 0;

    // 作れない数を探す
    for (long i = 1; i <= n; ++i) {
      bool flag = true;
      if (i % b == 0)
        continue;
      for (long j = 0; i - j * b > 0; ++j) {
        if ((i - j * b) % a == 0) {
          flag = false;
          break;
        }
      }
      if (flag)
        ++ans;
    }

    printf("%ld\\n", ans);
  }
}
Problem p00687 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define between(a, x, b) ((a) <= (x) && (x) <= (b))
#define F first
#define S second
#define INF 1 << 30

int main() {
  int n, a, b;
  while (scanf("%d%d%d", &n, &a, &b) && n + a + b) {
    bool f[2000000] = {};
    f[0] = 1;
    rep(i, n + 1) {
      if (!f[i])
        continue;
      f[i + a] = 1;
      f[i + b] = 1;
    }

    //    puts("error\\n");
    int res = 0;
    rep(i, n + 1) if (!f[i]) res++;

    printf("%d\\n", res);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define between(a, x, b) ((a) <= (x) && (x) <= (b))
#define F first
#define S second
#define INF 1 << 30

int main() {
  int n, a, b;
  while (scanf("%d%d%d", &n, &a, &b) && n + a + b) {
    bool f[1000001] = {};
    f[0] = 1;
    rep(i, n + 1) {
      if (!f[i])
        continue;
      f[i + a] = 1;
      f[i + b] = 1;
    }

    //    puts("error\\n");
    int res = 0;
    rep(i, n + 1) if (!f[i]) res++;

    printf("%d\\n", res);
  }
  return 0;
}