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

#include <cassert>
#include <iostream>
#define REP(i, l, n) for (int i = l; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define MAX 1000000
int ans;
int a, d, n;
bool prime[MAX];
using namespace std;
void era();
int main() {
  while (true) {
    era();
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      return 0;
    int i;
    for (i = a; n > 0; i += d) {
      if (prime[i])
        n--;
    }
    cout << i - d << endl;
  }
  return 0;
}

void era() {
  rep(i, MAX) prime[i] = true;
  prime[0] = false;
  prime[1] = false;
  for (int i = 4; i < MAX; i += 2)
    prime[i] = false;
  rep(i, MAX) {
    if (prime[i])
      for (int j = 3 * i; j < MAX; j += 2 * i) {
        prime[j] = false;
      }
  }
}

Error: TLE

Fixed submission:

#include <cassert>
#include <iostream>
#define REP(i, l, n) for (int i = l; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define MAX 1000000
int ans;
int a, d, n;
bool prime[MAX];
using namespace std;
void era();
int main() {
  while (true) {
    era();
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      return 0;
    int i;
    for (i = a; n > 0; i += d) {
      if (prime[i])
        n--;
    }
    cout << i - d << endl;
  }
  return 0;
}

void era() {
  rep(i, MAX) prime[i] = true;
  prime[0] = false;
  prime[1] = false;
  rep(i, MAX) {
    if (prime[i])
      for (int j = 2 * i; j < MAX; j += i) {
        prime[j] = false;
      }
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#include <cmath>
typedef long long ll;
ll prime[1000001];
ll length = 0;
bool isprime[1000000] = {};
void insert(ll p) {
  prime[length] = p;
  length++;
  isprime[p] = true;
  return;
}
void makeprime() {
  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:;
  }
}
int main() {
  makeprime();
  int a, d, n;
  while (cin >> a >> d >> n, a, d, n) {
    int cnt = 0;
    for (int i = a;; i += d) {
      if (isprime[i]) {
        cnt++;
        if (cnt == n) {
          cout << i << endl;
          goto end;
        }
      }
    }
  end:;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#include <cmath>
bool isprime(int n) {
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  for (int i = 3; i <= sqrt(n); i += 2)
    if (n % i == 0)
      return false;
  return true;
}
int main() {
  int a, d, n;
  while (cin >> a >> d >> n) {
    int cnt = 0;
    for (int i = a;; i += d) {
      if (isprime(i)) {
        cnt++;
        if (cnt == n) {
          cout << i << endl;
          goto end;
        }
      }
    }
  end:;
  }
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

const int MAX_SIZE = 1000000;

int prime[MAX_SIZE];
bool isPrime[MAX_SIZE];
int p;

int main() {

  fill(isPrime, isPrime + MAX_SIZE, true);
  p = 0;
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i <= MAX_SIZE; i++) {
    if (isPrime[i]) {
      prime[p++] = i;
    } else
      continue;
    for (int j = 2 * i; j <= MAX_SIZE; j += i) {
      isPrime[j] = false;
    }
  }

  int a, d, n;
  while (cin >> a >> d >> n && !(a == 0 && d == 0 && n == 0)) {
    int cnt = 0;
    for (int i = 0;; i++) {
      int num = a + i * d;
      if (isPrime[num]) {
        cnt++;
      }
      if (cnt == n) {
        cout << num << endl;
        break;
      }
    }
  }

  return 0;
}

Error: -11

Fixed submission:

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

using namespace std;

const int MAX_SIZE = 100000;

int prime[MAX_SIZE];
bool isPrime[MAX_SIZE];
int p;

int main() {

  fill(isPrime, isPrime + MAX_SIZE, true);
  p = 0;
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i <= MAX_SIZE; i++) {
    if (isPrime[i]) {
      prime[p++] = i;
    } else
      continue;
    for (int j = 2 * i; j <= MAX_SIZE; j += i) {
      isPrime[j] = false;
    }
  }

  int a, d, n;
  while (cin >> a >> d >> n && !(a == 0 && d == 0 && n == 0)) {
    int cnt = 0;
    for (int i = 0;; i++) {
      int num = a + i * d;
      if (isPrime[num]) {
        cnt++;
      }
      if (cnt == n) {
        cout << num << endl;
        break;
      }
    }
  }

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

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int a, d, n;
  while (cin >> a >> d >> n) {
    if (a == 0)
      break;
    int ct = 0, m = -1;
    while (ct < n) {
      m++;
      int i = a + d * m;
      ct++;
      if (i > 2 && i % 2 == 0) {
        ct--;
      } else if (i > 3 && i % 3 == 0) {
        ct--;
      } else if (i > 5 && i % 5 == 0) {
        ct--;
      } else if (i > 7 && i % 7 == 0) {
        ct--;
      } else {
        for (int k = 1; k < sqrt(i) + 3; k++) {
          if (i > 71 && i % (6 * k - 1) == 0) {
            ct--;
            goto end;
          } else if (i > 73 && i % (6 * k + 1) == 0) {
            ct--;
            goto end;
          }
        }
        if (i == 1)
          ct--;
      }
    end:;
    }
    cout << a + d * m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, d, n;
  while (cin >> a >> d >> n) {
    if (a == 0)
      break;
    int ct = 0, m = -1;
    while (ct < n) {
      m++;
      int i = a + d * m;
      ct++;
      if (i > 2 && i % 2 == 0) {
        ct--;
      } else if (i > 3 && i % 3 == 0) {
        ct--;
      } else if (i == 5 || i == 7 || i == 11 || i == 13) {
      } else {
        for (int k = 1; k < (i / 12) + 2; k++) {
          if (i % (6 * k - 1) == 0) {
            ct--;
            goto end;
          } else if (i % (6 * k + 1) == 0) {
            ct--;
            goto end;
          }
        }
        if (i == 1)
          ct--;
      }
    end:;
    }
    cout << a + d * m << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
using namespace std;

#define INF 1 << 21
#define MOD 1000000007
#define MAX 1000000

int main() {
  char p[MAX];
  memset(p, 1, sizeof(p));
  p[0] = 0;
  p[1] = 0;
  for (int i = 2; i <= sqrt(MAX) + 1; i++) {
    if (p[i] == 1) {
      for (int j = 2 * i; j <= MAX; j += i) {
        p[j] = 0;
      }
    }
  }

  int a, d, n;
  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      return 0;
    while (1) {
      if (p[a] == 1)
        n--;
      if (n == 0) {
        cout << a << endl;
        break;
      }
      a += d;
    }
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
using namespace std;

#define INF 1 << 21
#define MOD 1000000007
#define MAX 1000000

int main() {
  int p[MAX];
  memset(p, 1, sizeof(p));
  p[0] = 0;
  p[1] = 0;
  for (int i = 2; i <= sqrt(MAX) + 1; i++) {
    if (p[i] == 1) {
      for (int j = 2 * i; j <= MAX; j += i) {
        p[j] = 0;
      }
    }
  }

  int a, d, n;
  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      return 0;
    while (1) {
      if (p[a] == 1)
        n--;
      if (n == 0) {
        cout << a << endl;
        break;
      }
      a += d;
    }
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
using namespace std;

#define INF 1 << 21
#define MOD 1000000007

int main() {
  char p[1000005];
  memset(p, 1, sizeof(p));
  p[0] = 0;
  p[1] = 0;
  for (int i = 2; i <= 1000; i++) {
    if (p[i] == 1) {
      for (int j = 2 * i; j <= 1000000; j += i) {
        p[j] = 0;
      }
    }
  }

  int a, d, n;
  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      return 0;
    while (1) {
      if (p[a] == 1)
        n--;
      if (n == 0) {
        cout << a << endl;
        break;
      }
      a += d;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
using namespace std;

#define INF 1 << 21
#define MOD 1000000007

int prime(int a) {
  int x = 1;
  if (a == 1)
    return 0;
  for (int i = 2; i <= a / 2; i++) {
    if (a % i == 0)
      x = 0;
  }
  return x;
}

int main() {
  int a, d, n;
  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      return 0;

    while (1) {
      if (prime(a) == 1)
        n--;
      if (n == 0) {
        cout << a << endl;
        break;
      }
      a += d;
    }
  }
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int a[1000000] = {0, 0, 1, 1}, n, k = 0;
  for (int i = 4; i < 1000000; i++) {
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        k++;
        break;
      }
    }
    if (!k)
      a[i]++;
    k = 0;
  }
  int b, c, d, x, s, q;
  while (cin >> b >> c >> d, b != 0 && c != 0 && d != 0) {
    s = x = q = 0;
    while (1) {
      x = b + c * s;
      if (a[x] == 1)
        q++;
      if (q == d)
        break;
      s++;
    }
    cout << x << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[100000] = {0, 0, 1, 1}, n, k = 0;
  for (int i = 4; i < 100000; i++) {
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        k++;
        break;
      }
    }
    if (!k)
      a[i]++;
    k = 0;
  }
  int b, c, d, x, s, q;
  while (cin >> b >> c >> d, b != 0 && c != 0 && d != 0) {
    s = x = q = 0;
    while (1) {
      x = b + c * s;
      if (a[x] == 1)
        q++;
      if (q == d)
        break;
      s++;
    }
    cout << x << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define int long long

vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i * i < n; ++i)
    if (primes[i])
      for (int j = i * i; j < n; j += i)
        primes[j] = 0;

  primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
  return primes;
}

signed main() {
  int a, d, n;
  vector<int> primes = sieve_of_eratosthenes(1000001);
  while (cin >> a >> d >> n, a) {
    int cnt = 0;
    int ans = 0;
    for (int i = a;; i += d) {
      if (*lower_bound(primes.begin(), primes.end(), i) == i)
        cnt++;
      if (cnt == n) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define int long long

vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i * i < n; ++i)
    if (primes[i])
      for (int j = i * i; j < n; j += i)
        primes[j] = 0;

  primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
  return primes;
}

signed main() {
  int a, d, n;
  vector<int> primes = sieve_of_eratosthenes(1000001);
  while (cin >> a >> d >> n, a) {
    int cnt = 0;
    int ans = 0;
    for (int i = a;; i += d) {
      if (find(primes.begin(), primes.end(), i) != primes.end())
        cnt++;
      if (cnt == n) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <math.h>
#include <stdio.h>

int main(void) {
  unsigned int a, d, n;
  // unsigned int sosu[999999] = {0};
  unsigned int *sosu = new unsigned int[999999];
  unsigned int sosunum;

  unsigned int sqnum = (int)sqrt((double)999999);

  for (unsigned int i = 0; i < 999999; i++) {
    sosu[i] = 1;
  }

  sosu[0] = 0;

  for (unsigned int i = 1; i < sqnum; i++) {
    if (sosu[i] == 1) {
      for (unsigned int j = i + 1; (i + 1) * j <= 999999; j++) {
        sosu[(i + 1) * j - 1] = 0;
      }
    }
  }

  while (1) {
    sosunum = 0;
    scanf("%d%d%d", &a, &d, &n);
    if (a == 0 && d == 0 && n == 0) {
      break;
    }
    while (sosunum != n) {
      if (sosu[a - 1]) {
        sosunum++;
      }
      a += d;
    }
    printf("%d\\n", a - d);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>

int eratosu(unsigned int n) {
  unsigned int sqnum = (int)sqrt((double)n);
  int *a = new int[n];

  int r;

  for (unsigned int i = 0; i < n; i++) {
    a[i] = 1;
  }

  a[0] = 0;

  for (unsigned int i = 1; i < sqnum; i++) {
    if (a[i] == 1) {
      for (unsigned int j = i + 1; (i + 1) * j <= n; j++) {
        a[(i + 1) * j - 1] = 0;
      }
    }
  }
  r = a[n - 1];
  delete[] a;

  return r;
}

int main(void) {
  unsigned int a, d, n;
  unsigned int sosu[210];
  unsigned int sosunum;
  while (1) {
    sosunum = 0;
    scanf("%d%d%d", &a, &d, &n);
    if (a == 0 && d == 0 && n == 0) {
      break;
    }
    while (sosunum != n) {
      if (eratosu(a)) {
        sosu[sosunum] = a;
        sosunum++;
      }
      a += d;
    }
    printf("%d\\n", sosu[n - 1]);
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int prime(int x) {
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (int i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int a, d, n;
  while (scanf("%d %d %d", &a, &d, &n), a, d, n) {
    vector<int> v;
    for (int i = a; i <= 1000000; i += d) {
      if (prime(i))
        v.push_back(i);
    }
    printf("%d\\n", v[n - 1]);
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll prime(ll x) {
  ll i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int a, d, n;
  while (scanf("%d %d %d", &a, &d, &n), a, d, n) {
    vector<int> v;
    for (int i = a; i <= 1000000; i += d) {
      if (prime(i))
        v.push_back(i);
    }
    printf("%d\\n", v[n - 1]);
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <math.h>
#include <stdio.h>

int main();
bool prime_chk(int num);

int main() {

  int a[1000] = {0};
  int d[1000] = {0};
  int n[1000] = {0};
  int result[1000] = {0};
  int n_series;
  int s_series;
  int nth_prime_num;
  int i, i_dataset;

  bool prime_flg;

  // データ入力
  i_dataset = 0;
  while (1) {
    scanf("%d %d %d", &a[i_dataset], &d[i_dataset], &n[i_dataset]);

    if (a[i_dataset] == 0 && d[i_dataset] == 0 && n[i_dataset] == 0)
      break; // 0 0 0が入力されると処理終了
    else
      i_dataset++; // データ数を記録
  }

  // 計算開始

  for (i = 0; i < i_dataset; i++) {

    nth_prime_num = 0;
    n_series = 1;

    while (1) {
      if (n_series == 1)
        s_series = a[i];
      else
        s_series = a[i] + (n_series - 1) * d[i];

      prime_flg = prime_chk(s_series);
      if (prime_flg == true)
        nth_prime_num++;

      if (nth_prime_num == n[i]) {
        result[i] = s_series;
        break;
      }

      n_series++;
    }
  }

  for (i = 0; i < i_dataset; i++) {
    printf("%d\\n", result[i]); // 結果出力
  }

  return 0;
}

bool prime_chk(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrt_num = sqrt(num);
  for (int i = 3; i <= sqrt_num; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}


Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>

int main();
bool prime_chk(int num);

int main() {

  int a[100] = {0};
  int d[100] = {0};
  int n[100] = {0};
  int result[100] = {0};
  int n_series;
  int s_series;
  int nth_prime_num;
  int i, i_dataset;

  bool prime_flg;

  // データ入力
  i_dataset = 0;
  while (1) {
    scanf("%d %d %d", &a[i_dataset], &d[i_dataset], &n[i_dataset]);

    if (a[i_dataset] == 0 && d[i_dataset] == 0 && n[i_dataset] == 0)
      break; // 0 0 0が入力されると処理終了
    else
      i_dataset++; // データ数を記録
  }

  // 計算開始

  for (i = 0; i < i_dataset; i++) {

    nth_prime_num = 0;
    n_series = 1;

    while (1) {
      if (n_series == 1)
        s_series = a[i];
      else
        s_series = a[i] + (n_series - 1) * d[i];

      prime_flg = prime_chk(s_series);
      if (prime_flg == true)
        nth_prime_num++;

      if (nth_prime_num == n[i]) {
        result[i] = s_series;
        break;
      }

      n_series++;
    }
  }

  for (i = 0; i < i_dataset; i++) {
    printf("%d\\n", result[i]); // 結果出力
  }

  return 0;
}

bool prime_chk(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrt_num = sqrt(num);
  for (int i = 3; i <= sqrt_num; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
#define MAX_N 1000000

int sosuu[MAX_N];

void sosu(void) {
  int i, j;
  for (i = 2; i <= MAX_N; i++) {
    sosuu[i] = 1;
  }

  sosuu[0] = 0;
  sosuu[1] = 0;

  for (i = 2; i <= MAX_N; i++) {
    if (sosuu[i]) {
      for (j = i * 2; j <= MAX_N; j += i) {
        sosuu[j] = 0;
      }
    }
  }
}

int main(void) {
  sosu();

  for (;;) {
    int a, d, n;
    scanf("%d %d %d", &a, &d, &n);
    if (a == 0 || d == 0 || n == 0)
      return 0;

    int count = 0;
    int i;
    for (i = a;; i += d) {
      // printf("count=%d i=%d\\n",count,i);
      if (sosuu[i] == 1)
        count++;
      if (count == n)
        break;
    }
    printf("%d\\n", i);
  }
  return 1;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int a, d, n, i, j, k, l = 0, tmp, count = 0;
  int prime[100001];
  for (i = 2; i <= 100000; i++) {
    prime[i] = 1;
  }
  prime[0] = 0;
  prime[1] = 0;

  for (;;) {
    l = 0;
    scanf("%d %d %d", &a, &d, &n);
    if (a == 0 && d == 0 && n == 0) {
      return 0;
    }
    // printf("1");
    count = 0;
    for (i = 0;; i++) {
      tmp = a + d * i;
      if (prime[tmp]) {
        for (j = 2; j < tmp; j++) {
          if (tmp % j == 0) {
            prime[tmp] = 0;
            for (k = tmp; k <= 100000; k += tmp) {
              prime[k] = 0;
            }
            break;
          } else if (j == (tmp - 1)) {
            count++;
            // printf("%d\\n",count);
            if (count == n) {
              l = 1;
              printf("%d\\n", tmp);
              break;
            }
          }
        }
      }
      if (l == 1) {
        break;
      }
    }
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
const int MAX_N = 1000000; // いくつまで調べるか
bool prime[MAX_N + 1];     // 添字が素数ならtrue、それ以外はfalse
void sieve() {
  prime[0] = prime[1] = false; // 例外処理
  // 配列prime の初期化
  for (int i = 2; i <= MAX_N; ++i)
    prime[i] = true;
  // 素数でないものを調べる
  for (int i = 2; i <= MAX_N; ++i)
    if (prime[i])
      for (int j = i * 2; j <= MAX_N; j += i)
        prime[j] = false;
}
int is_prime(int n) { return prime[n]; } //*/

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

int main() {
  sieve();
  int a, d, n;
  for (;;) {
    cin >> a >> d >> n;
    if (d == 0)
      return 0;
    int now, count = 0;
    int tmp;
    for (int i = a; i < 1000000; i += d) {
      if (is_prime(i))
        count++;
      if (count == n) {
        printf("%d\\n", i);
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
const int MAX_N = 1000000; // いくつまで調べるか
bool prime[MAX_N + 1];     // 添字が素数ならtrue、それ以外はfalse
void sieve() {
  prime[0] = prime[1] = false; // 例外処理
  // 配列prime の初期化
  for (int i = 2; i <= MAX_N; ++i)
    prime[i] = true;
  // 素数でないものを調べる
  for (int i = 2; i <= MAX_N; ++i)
    if (prime[i])
      for (int j = i * 2; j <= MAX_N; j += i)
        prime[j] = false;
}
/*int is_prime(int n)
{
  return prime[n];
  }*/

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

int main() {
  int a, d, n;
  for (;;) {
    cin >> a >> d >> n;
    if (d == 0)
      return 0;
    int now, count = 0;
    int tmp;
    for (int i = a; i < 1000000; i += d) {
      if (is_prime(i))
        count++;
      if (count == n) {
        printf("%d\\n", i);
        break;
      }
    }
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MAX_NUMBER 1000001
int main(void) {
  bool sosu[MAX_NUMBER];

  for (int i = 1; i < MAX_NUMBER; i++) {
    sosu[i] = true;
  }

  sosu[1] = false;
  for (int i = 2; i < MAX_NUMBER / 2; i++) {
    for (int j = 2; i * j < MAX_NUMBER; j++) {
      sosu[i * j] = false;
    }
  }

  for (;;) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;

    int cnt = 0;
    for (int i = 1; a + (i - 1) * d < MAX_NUMBER; i++) {
      int num = a + (i - 1) * d;
      if (sosu[num]) {
        cnt++;
      }
      if (cnt == n) {
        printf("%d\\n", num);
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

bool sosu(int num) {
  for (int i = 2; i < num; i++) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}

int main(void) {
  for (;;) {
    int n, a, d;
    cin >> a >> d >> n;

    if (n == 0 && a == 0 && d == 0)
      break;

    int cnt = 0;
    for (int i = 0; a + i * d < 1000000; i++) {
      int num = a + i * d;
      if (sosu(num)) {
        cnt++;
      }
      if (cnt == n) {
        printf("%d\\n", a + i * d);
        break;
      }
    }
  }
}