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

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

struct hoge {
  int num, timem, times;
};

int main() {
  int n, c, m1, s1, m2, s2, m3, s3, m4, s4;
  hoge set[1000000];
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      set[i].num = c;
      set[i].timem = m1 + m2 + m3 + m4;
      set[i].times = s1 + s2 + s3 + s4;
      if (set[i].times >= 60) {
        set[i].timem += set[i].times / 60;
        set[i].times %= 60;
      }
    }

    for (int i = 0; i < (n - 1); i++) {
      for (int j = (i + 1); j < n; j++) {
        if (set[j].timem < set[i].timem) {
          swap(set[i].num, set[j].num);
          swap(set[i].timem, set[j].timem);
          swap(set[i].times, set[j].times);
        } else if (set[j].timem == set[i].timem) {
          if (set[j].times < set[i].times) {
            swap(set[i].num, set[j].num);
            swap(set[i].timem, set[j].timem);
            swap(set[i].times, set[j].times);
          }
        }
      }
    }

    cout << set[0].num << endl << set[1].num << endl << set[n - 2].num << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

struct hoge {
  int num, timem, times;
};

int main() {
  int n, c, m1, s1, m2, s2, m3, s3, m4, s4;
  hoge set[100];
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      set[i].num = c;
      set[i].timem = m1 + m2 + m3 + m4;
      set[i].times = s1 + s2 + s3 + s4;
      if (set[i].times >= 60) {
        set[i].timem += set[i].times / 60;
        set[i].times %= 60;
      }
    }

    for (int i = 0; i < (n - 1); i++) {
      for (int j = (i + 1); j < n; j++) {
        if (set[j].timem < set[i].timem) {
          swap(set[i].num, set[j].num);
          swap(set[i].timem, set[j].timem);
          swap(set[i].times, set[j].times);
        } else if (set[j].timem == set[i].timem) {
          if (set[j].times < set[i].times) {
            swap(set[i].num, set[j].num);
            swap(set[i].timem, set[j].timem);
            swap(set[i].times, set[j].times);
          }
        }
      }
    }

    cout << set[0].num << endl << set[1].num << endl << set[n - 2].num << endl;
  }
  return 0;
}
Problem p00161 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int h, n, i, j, sum[100000], xmax = 0, num1[100000], num2[100000];

  while (1) {
    xmax = 0;
    for (i = 0; i < 100000; i++)
      sum[i] = 0;

    cin >> n;
    if (n == 0)
      break;

    for (i = 0; i < n; i++) {
      cin >> num1[i];
      for (j = 1; j < 9; j++) {

        cin >> num2[j];

        if (j > 0 && j % 2 == 0) {
          sum[i] += num2[j];
        } else if (j > 0 && j % 2 != 0) {
          sum[i] += (num2[j] * 60);
        }
      }
    }

    for (i = 0; i < n; i++) {
      xmax = i;
      for (j = i; j < n; j++) {
        if (sum[xmax] < sum[j])
          xmax = j;
      }
      h = sum[xmax];
      sum[xmax] = sum[i];
      sum[i] = h;

      h = num1[xmax];
      num1[xmax] = num1[i];
      num1[i] = h;
    }
    /*

    for(i=0;i<n;i++){
        cout << "num1["<<i<<"]="<<num1[i];
        cout << "  sum["<<i<<"]="<<sum[i];
      cout << endl;
    }

    */

    cout << num1[n - 1] << endl;
    cout << num1[n - 2] << endl;
    cout << num1[1] << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int h, n, i, j, num[1000][1000], sum[1000], xmax = 0;

  while (1) {
    xmax = 0;
    for (i = 0; i < 100; i++)
      sum[i] = 0;

    cin >> n;
    for (i = 0; i < n; i++) {

      for (j = 0; j < 9; j++) {
        cin >> num[i][j];

        if (j > 0 && j % 2 == 0) {
          sum[i] += num[i][j];
        } else if (j > 0 && j % 2 != 0) {
          sum[i] += (num[i][j] * 60);
        }
      }
    }

    for (i = 0; i < n; i++) {
      xmax = i;
      for (j = i; j < n; j++) {
        if (sum[xmax] < sum[j])
          xmax = j;
      }
      h = sum[xmax];
      sum[xmax] = sum[i];
      sum[i] = h;

      h = num[xmax][0];
      num[xmax][0] = num[i][0];
      num[i][0] = h;
    }

    /*
    for(i=0;i<n;i++){
        cout << "num["<<i<<"][0]="<<num[i][0];
        cout << "  sum["<<i<<"]="<<sum[i];
      cout << endl;
    }
    */

    cout << num[n - 1][0] << endl;
    cout << num[n - 2][0] << endl;
    cout << num[1][0] << endl;
  }
}
Problem p00162 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

const int MAX = 1000001;

int main() {
  bool h[MAX] = {};
  for (int i = 1; i < MAX; i *= 2) {
    for (int j = i; j < MAX; j *= 3) {
      for (int k = j; k < MAX; k *= 5)
        h[k] = 1;
    }
  }
  int m;
  while (cin >> m, m) {
    int n, count = 0;
    cin >> n;
    for (int i = m; i <= n; i++)
      if (h[i])
        count++;
    cout << count << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int m, n;

int check(int num) {
  if (m <= num && num <= n)
    return 1;
  return 0;
}

int main(int argc, char *argv[]) {
  while (cin >> m >> n, m) {
    int base = 1;
    int ans = 0;
    for (int i = int(m / 2); i <= int(n / 2); ++i) {
      for (int j = int(m / 3); j <= int(n / 3); ++j) {
        for (int k = int(m / 5); k <= int(n / 5); ++k) {
          ans += check(pow(2, i) * pow(3, j) * pow(5, k));
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00162 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define D 1000000
using namespace std;
bool flg[D];
int ans[D];
int main() {

  int m, n;
  flg[1] = true;
  for (int i = 0; i <= D; i++) {
    if (flg[i]) {
      if (2 * i <= D)
        flg[2 * i] = true;
      if (3 * i <= D)
        flg[3 * i] = true;
      if (5 * i <= D)
        flg[5 * i] = true;
      // cout<<i<<endl;
    }
  }
  int cnt = 0;
  for (int i = 0; i <= D; i++) {
    if (flg[i])
      cnt++;
    ans[i] = cnt;
    // cout<<ans[i]<<endl;
  }
  while (cin >> m, m) {
    cin >> n;
    cout << ans[n] - ans[m - 1] << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#define D 100
using namespace std;
bool flg[D];
int ans[D];
int main() {

  int m, n;
  flg[1] = true;
  for (int i = 0; i <= D; i++) {
    if (flg[i]) {
      if (2 * i <= D)
        flg[2 * i] = true;
      if (3 * i <= D)
        flg[3 * i] = true;
      if (5 * i <= D)
        flg[5 * i] = true;
      // cout<<i<<endl;
    }
  }
  int cnt = 0;
  for (int i = 0; i <= D; i++) {
    if (flg[i])
      cnt++;
    ans[i] = cnt;
    // cout<<ans[i]<<endl;
  }
  while (cin >> m, m) {
    cin >> n;
    cout << ans[n] - ans[m - 1] << endl;
  }
}
Problem p00162 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int l, r;
  while (cin >> l >> r) {
    int ans = 0;
    for (int i = l; i <= r; i++) {
      int q = i;
      while (q % 2 == 0)
        q /= 2;
      while (q % 3 == 0)
        q /= 3;
      while (q % 5 == 0)
        q /= 5;
      if (q == 1)
        ans++;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  long long m, n;
  vector<long long> l;
  while (cin >> m) {
    if (m == 0)
      break;
    cin >> n;
    long long sum = 0;
    for (int i = m; i <= n; i++) {
      if (2 ^ 22 * 3 ^ 15 * 5 ^ 10 % i == 0) {
        sum++;
      }
    }
    l.push_back(sum);
  }
  for (long long i : l) {
    cout << i << endl;
  }
  char c;
  cin >> c;
}
Problem p00162 (C++) — buggy submission, verdict: Runtime Error

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

const int MAX_NUM = 1000000;

int main() {
  bool list[MAX_NUM + 1] = {0};

  for (int two = 0; two <= 20; two++) {
    for (int three = 0; three <= 13; three++) {
      for (int five = 0; five <= 9; five++) {
        int num = pow(2, two) * pow(3, three) * pow(5, five);
        if (1 <= num && num <= MAX_NUM)
          list[num] = true;
      }
    }
  }
  int m, n;
  while (1) {
    cin >> m;
    if (m == 0)
      break;
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++) {
      if (list[i])
        ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

const int MAX_NUM = 1000;

int main() {
  bool list[MAX_NUM + 1] = {0};

  for (int two = 0; two <= 20; two++) {
    for (int three = 0; three <= 13; three++) {
      for (int five = 0; five <= 9; five++) {
        int num = pow(2, two) * pow(3, three) * pow(5, five);
        if (1 <= num && num <= MAX_NUM)
          list[num] = true;
      }
    }
  }
  int m, n;
  while (1) {
    cin >> m;
    if (m == 0)
      break;
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++) {
      if (list[i])
        ans++;
    }
    cout << ans << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI = 6 * asin(0.5);
typedef pair<double, double> P;
typedef complex<double> CP;
typedef long long ll;

bool a[1000010];
int b[1000010] = {0};

int main() {
  for (ll i = 0; i < 1000010; i++) {
    a[i] = false;
  }
  a[1] = true;
  for (ll i = 1; i < 1000010; i++) {
    if (a[i]) {
      if (2 * i < 1000010)
        a[2 * i] = true;
      if (3 * i < 1000010)
        a[3 * i] = true;
      if (5 * i < 1000010)
        a[5 * i] = true;
    }
  }
  /*
  rep(i,100){
          if(a[i]){
                  cout<<i<<" ";
          }
  }
  cout<<endl;
  */
  for (ll i = 1; i < 1000010; i++) {
    // if(i==0) continue;
    b[i] = b[i - 1];
    if (a[i])
      b[i]++;
  }
  ll m, n;
  while (cin >> m, m) {
    cin >> n;
    if (a[m])
      cout << b[n] - b[m] + 1 << endl;
    else
      cout << b[n] - b[m] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI = 6 * asin(0.5);
typedef pair<double, double> P;
typedef complex<double> CP;
typedef long long ll;

bool a[1000010];
int b[1000010] = {0};

int main() {
  rep(i, 1000010) { a[i] = false; }
  a[1] = true;
  for (int i = 1; i < 1000010; i++) {
    if (a[i]) {
      a[2 * i] = true;
      a[3 * i] = true;
      a[5 * i] = true;
    }
  }
  rep(i, 1000010) {
    if (i == 0)
      continue;
    b[i] = b[i - 1];
    if (a[i])
      b[i]++;
  }
  int m, n;
  while (cin >> m, m) {
    cin >> n;
    cout << b[n] - b[m] + 1 << endl;
  }
  return 0;
}
Problem p00162 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int m;
  int n, a, cnt;
  m = 0, n = 0, a = 0, cnt = 0;
  while (1) {
    cin >> m;
    if (m == 0)
      break;
    cin >> n;

    for (int i = m; i <= n; i++) {
      a = i;

      while (a % 2 == 0)
        a = a / 2;
      while (a % 3 == 0)
        a = a / 3;
      while (a % 5 == 0)
        a = a / 5;

      if (a == 1)
        cnt++;
    }

    cout << cnt << endl;
    cnt = 0;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int m;
  int n, a, cnt;
  m = 0, n = 0, a = 0, cnt = 0;
  while (1) {
    cin >> m;
    if (m == 0)
      break;
    cin >> n;

    for (int i = m; i < n; i++) {
      a = i;

      while (a / 2 == 0)
        a = a / 2;
      while (a / 3 == 0)
        a = a / 3;
      while (a / 5 == 0)
        a = a / 5;

      if (a == 1)
        cnt++;
    }

    cout << cnt << endl;
    cnt = 0;
  }
}
Problem p00162 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

using namespace std;

int main() {
  int m;
  vector<unsigned short> count;
  for (int i = 0; i < 6; i++)
    count.push_back(i);
  for (int i = 6; i < 10000001; i++) {
    if ((i % 2 == 0 && count[i / 2] - count[(i / 2) - 1] != 0) ||
        (i % 3 == 0 && count[i / 3] - count[(i / 3) - 1] != 0) ||
        (i % 5 == 0 && count[i / 5] - count[(i / 5) - 1] != 0))
      count.push_back(count[i - 1] + 1);
    else
      count.push_back(count[i - 1]);
  }
  for (; cin >> m, m;) {
    int n;
    cin >> n;
    cout << count[n] - count[m - 1] << endl;
  }
}

Error: MLE

Fixed submission:

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

using namespace std;

int main() {
  int m;
  vector<int> count;
  for (int i = 0; i < 6; i++)
    count.push_back(i);
  for (int i = 6; i < 10000001; i++) {
    if ((i % 2 == 0 && count[i / 2] - count[(i / 2) - 1] != 0) ||
        (i % 3 == 0 && count[i / 3] - count[(i / 3) - 1] != 0) ||
        (i % 5 == 0 && count[i / 5] - count[(i / 5) - 1] != 0))
      count.push_back(count[i - 1] + 1);
    else
      count.push_back(count[i - 1]);
  }
  for (; cin >> m, m;) {
    int n;
    cin >> n;
    cout << count[n] - count[m - 1] << endl;
  }
}
Problem p00162 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;
const int N_MAX = 1000000;

int main() {
  int res, st, ed;
  vector<bool> jud(N_MAX, false);
  jud[1] = true;

  for (int i = 1; i <= N_MAX / 2; i++) {
    if (jud[i]) {
      jud[i * 2] = true;
      if (i * 3 <= N_MAX) {
        jud[i * 3] = true;
      }
      if (i * 5 <= N_MAX) {
        jud[i * 5] = true;
      }
    }
  }

  while (cin >> st, st) {
    cin >> ed;
    res = 0;
    for (int i = st; i <= ed; i++) {
      if (jud[i]) {
        res++;
      }
    }
    cout << res << endl;
  }
}

Error: -11

Fixed submission:

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

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;
#define N_MAX 1000000

int main() {
  int res, st, ed;
  vector<bool> jud(N_MAX, false);
  jud[1] = true;

  for (int i = 1; i <= N_MAX / 2; i++) {
    if (jud[i]) {
      jud[i * 2] = true;
      jud[i * 3] = true;
      jud[i * 5] = true;
    }
  }

  while (cin >> st, st) {
    cin >> ed;
    res = 0;
    for (int i = st; i <= ed; i++) {
      if (jud[i]) {
        res++;
      }
    }
    cout << res << endl;
  }
}
Problem p00162 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define EPS 1e-10
using namespace std;
typedef long long llong;
static const int lim = 1000001;
vector<int> dp(lim, 0);
int main() {

  for (int s = 1; s < lim; s *= 2) {
    for (int t = s; t < lim; t *= 3) {
      for (int u = t; u < lim; u *= 5) {
        dp[u] = 1;
      }
    }
  }
  for (int i = 1; i < lim; i++)
    dp[i] += dp[i - 1];

  int m, n;
  while (cin >> m >> n, m) {
    cout << dp[n] - dp[m - 1] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
  int m, n;
  vector<int> v(1000001, 1);
  v[0] = v[1] = 0;
  for (int i = 2; i <= sqrt(1000000); i++) {
    if (v[i]) {
      for (int j = 0; i * (j + 2) <= 1000000; j++) {
        v[i * (j + 2)] = 0;
      }
    }
  }
  // for (int i = 2; i < 100; i++) {
  //	if (v[i])printf("%4d", i);
  // }
  // cout << endl;

  while (cin >> m >> n, m) {
    int cnt = 0;
    for (int i = m; i <= n; i++) {
      if (i == 1)
        cnt++;
      bool f = false;
      bool g = false;
      if (i % 2 == 0 || i % 3 == 0 || i % 5 == 0) {
        g = true;
      }
      for (int j = 7; j < i; j++) {
        if (v[j] && i % j == 0) {
          f = true;
          break;
        }
      }
      if (!f && g)
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00162 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

bool isHamming(int x) {
  int j = x;
  while (j % 2 == 0)
    j = j / 2;
  while (j % 3 == 0)
    j = j / 3;
  while (j % 5 == 0)
    j = j / 5;
  if (j == 1)
    return true;
  else
    return false;
}

int main() {

  while (true) {
    int m, n;
    cin >> m;

    if (m == 0)
      break;

    cin >> n;

    int ans = 0;
    for (int i = m; i <= n; i++) {
      if (isHamming(i))
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int x = 100000;
  bool isHamming[x];
  isHamming[0] = false;
  for (int i = 1; i < x; i++)
    isHamming[i] = true;
  for (int i = 1; i < x; i++) {
    int j = i;
    while (j % 2 == 0)
      j = j / 2;
    while (j % 3 == 0)
      j = j / 3;
    while (j % 5 == 0)
      j = j / 5;
    if (j == 1)
      isHamming[i] = false;
  }

  while (true) {
    int m, n;
    cin >> m;

    if (m == 0)
      break;

    cin >> n;

    int ans = 0;
    for (int i = m; i <= n; i++) {
      if (isHamming[i])
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00162 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()

const int MAXN = 1000000 + 10;

bool ham[MAXN];

int main() {
  ham[1] = 1;
  REP(MAXN) if (ham[i]) {
    for (int j = i * 2; j < MAXN; j *= 2)
      ham[j] = 1;
    for (int j = i * 3; j < MAXN; j *= 3)
      ham[j] = 1;
    for (int j = i * 5; j < MAXN; j *= 5)
      ham[j] = 1;
  }
  int m, n;
  while (cin >> m && m) {
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++)
      if (ham[i])
        ans++;
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()

const int MAXN = 100 * 1000 + 10;

bool ham[MAXN];

int main() {
  ham[1] = 1;
  REP(MAXN) if (ham[i]) {
    for (int j = i * 2; j < MAXN; j *= 2)
      ham[j] = 1;
    for (int j = i * 3; j < MAXN; j *= 3)
      ham[j] = 1;
    for (int j = i * 5; j < MAXN; j *= 5)
      ham[j] = 1;
  }
  int m, n;
  while (cin >> m && m) {
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++)
      if (ham[i])
        ans++;
    cout << ans << endl;
  }

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

#include <algorithm>
#include <iostream>

using namespace std;

bool prime[1000001];
int ans[1000001];

void erat() {

  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < 1000001; i++) {
    prime[i] = true;
  }

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

void solve() {
  ans[0] = 0;
  for (int i = 1; i < 1000001; i++) {
    ans[i] = 1;
  }
  for (int i = 7; i < 1000001; i++) {
    if (prime[i]) {
      for (int j = 2; i * j < 1000001; j++) {
        ans[i * j] = 0;
      }
      ans[i] = 0;
    }
  }
  for (int i = 1; i < 1000001; i++) {
    ans[i] += ans[i - 1];
  }
}

int main() {
  int m, n;
  cin >> m;

  erat();
  solve();

  while (m) {
    cin >> n;
    cout << ans[n] - ans[m - 1] << endl;
    cin >> m;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

bool prime[10000];
int ans[1000001];

void erat() {

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

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

void solve() {
  ans[0] = 0;
  for (int i = 1; i < 1000001; i++) {
    ans[i] = 1;
  }
  for (int i = 7; i < 1000001; i++) {
    if (prime[i]) {
      for (int j = 2; i * j < 1000001; j++) {
        ans[i * j] = 0;
      }
      ans[i] = 0;
    }
  }
  for (int i = 1; i < 1000001; i++) {
    ans[i] += ans[i - 1];
  }
}

int main() {
  int m, n;
  cin >> m;

  erat();
  solve();

  while (m) {
    cin >> n;
    cout << ans[n] - ans[m - 1] << endl;
    cin >> m;
  }
  return 0;
}
Problem p00162 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

bool ham[1000001];
int m, n;

void solve() {
  ham[1] = true;
  for (int i = 2; i < 1000001; i++)
    ham[i] = false;
  for (int i = 1; i < 1000001; i++) {
    if (ham[i]) {
      for (int j = i * 2; j < 1000001; j *= 2)
        ham[j] = true;
      for (int j = i * 3; j < 1000001; j *= 3)
        ham[j] = true;
      for (int j = i * 5; j < 1000001; j *= 5)
        ham[j] = true;
    }
  }
}

int main() {
  solve();
  while (true) {
    cin >> m;
    if (!m)
      return 0;
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++)
      if (ham[i])
        ans++;
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool ham[1000001];
int m, n;

void solve() {
  ham[1] = true;
  for (int i = 2; i < 1000001; i++)
    ham[i] = false;
  for (int i = 1; i < 1000001; i++) {
    if (ham[i]) {
      for (int j = i * 2; j < 1000001; j *= 2)
        ham[j] = true;
      for (int j = i * 3; j < 1000001; j *= 3)
        ham[j] = true;
      for (int j = i * 5; j < 1000001; j *= 5)
        ham[j] = true;
    }
  }
}

int main() {
  solve();
  while (true) {
    cin >> m >> n;
    if (!m && !n)
      return 0;
    int ans = 0;
    for (int i = m; i <= n; i++)
      if (ham[i])
        ans++;
    cout << ans << endl;
  }
}