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

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

const int MAX_N = 1000000;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

int main(void) {

  int p = 0;
  for (int i = 0; i <= 1000000; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;

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

  int a, d, n;
  while (1) {
    cin >> a >> d >> n;
    if (!n)
      break;
    int i = a;
    int j = 0;
    while (1) {
      if (is_prime[i + j * d])
        n--;
      if (n == 0) {
        cout << i + j * d << endl;
        break;
      }
      j++;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

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

const int MAX_N = 100000;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

int main(void) {

  int p = 0;
  for (int i = 0; i <= 100000; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;

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

  int a, d, n;
  while (1) {
    cin >> a >> d >> n;
    if (!n)
      break;
    int i = a;
    int j = 0;
    while (1) {
      if (is_prime[i + j * d])
        n--;
      if (n == 0) {
        cout << i + j * d << endl;
        break;
      }
      j++;
    }
  }

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

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

bool prime[1000000];

int main(void) {
  for (int i = 0; i < 1000000; i++)
    prime[i] = true;
  prime[0] = prime[1] = false;
  for (int i = 4; i < 1000000; i += 2)
    prime[i] = false;
  for (int i = 3; i < 1000000; i += 2) {
    for (int j = i + i; j < 1000000; j += i)
      prime[j] = false;
  }
  // for (int i = 0; i < 100; i++) if (prime[i]) cout << i << endl;
  int a, d, n;
  while (cin >> a >> d >> n, a && d, d && n) {
    int cnt = 0;
    int tmp = a;
    if (prime[tmp])
      cnt++;
    if (cnt == n)
      goto A;
    while (1) {
      tmp += d;
      if (prime[tmp])
        cnt++;
      if (cnt == n)
        break;
    }
  A:;
    cout << tmp << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool isPrime(int a) {
  if (a == 0 || a == 1)
    return false;
  if (a == 2)
    return true;
  if (a % 2 == 0)
    return false;
  for (int i = 3; i < a; i += 2) {
    if (a % i == 0)
      return false;
  }
  return true;
}

int main(void) {
  int a, d, n;
  while (cin >> a >> d >> n, a && d, d && n) {
    int cnt = 0;
    int tmp = a;
    if (isPrime(tmp))
      cnt++;
    if (cnt == n)
      goto A;
    while (1) {
      tmp += d;
      if (isPrime(tmp))
        cnt++;
      if (cnt == n)
        break;
    }
  A:;
    cout << tmp << endl;
  }

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

#include <iostream>
#define MAX 3000000
using namespace std;
int prime[MAX];
int isPrime[MAX + 1];

void seive(int n) {
  for (int i = 0; i < n; i++) {
    prime[i] = i;
    isPrime[i + 1] = true;
  }
  isPrime[0] = isPrime[1] = 0;
  for (int i = 2; i < n; i++) {
    if (isPrime[i] == true)
      for (int j = 2 * i; j < n; j += i)
        isPrime[j] = false;
  }
}

int main() {
  int a, b, n, count = 0, c = 0;
  seive(MAX);
  while (cin >> a >> b >> n, n) {
    count = 0;
    c = 0;
    for (int i = 0; count != n; i++) {
      if (isPrime[a + b * i] == true)
        count++;
      c++;
    }
    c--;
    cout << a + b * c << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int prime(int a, int d, int n) {
  int count = 0;
  bool flag = false;
  for (int i = 0; i < 10000; i++) {
    for (int j = 2; j < a + d * i; j++) {
      if ((a + d * i) % j == 0) {
        flag = true;
        break;
      }
    }
    if (flag == false)
      count++;
    if (count == n)
      return a + d * i;
    flag = false;
  }
  return 0;
}

int main() {
  int a, d, n;
  while (cin >> a >> d >> n, n) {
    int ans = prime(a, d, n);
    if (ans == 1)
      ans++;
    cout << ans << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int judge[1000000];
  for (int k = 0; k < 1000000; k++)
    judge[k] = 1;
  int a, d, n, i, j, sum, judge2 = 0;
  set<int> prime;

  prime.insert(2);

  // 999999までの素数リストをつくる。
  for (i = 3; i < 999999; i += 2) {
    if (judge[i] == 1) {
      prime.insert(i);
      for (j = 2; j <= 1000000 / i; j++) {
        judge[i * j] = 0;
      }
    }
  }

  while (1) {
    sum = 0;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;

    i = 0;
    while (1) {
      if (prime.find(a + i * d) != prime.end()) {
        sum++;
        if (sum == n) {
          cout << a + i * d << endl;
          break;
        }
      }
      i++;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

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

int main() {

  int judge[10000000];
  for (int k = 0; k < 10000000; k++)
    judge[k] = 1;
  int a, d, n, i, j, k = 1, sum, judge2 = 0;
  set<int> prime;

  prime.insert(2);
  sum = 0;

  cin >> a >> d >> n;
  i = 3;

  while (1) {
    // 100項目までの素数リストをつくる。
    for (; i < a + k * 100 * d; i += 2) {
      if (judge[i] == 1) {
        prime.insert(i);
        for (j = 2; j <= (a + k * 100 * d) / i; j++) {
          judge[i * j] = 0;
        }
      }
    }

    for (j = k - 100; j < k; j++) {
      if (prime.find(a + j * d) == prime.end()) {
        sum++;
        if (sum == n) {
          cout << a + j * d << endl;
          judge2 = 1;
          break;
        }
      }
    }
    if (judge2 == 1)
      break;
    i = a + k * 100 * d;
    k++;
  }

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

#include <iostream>
using namespace std;

int isPrime(int);
int count;
int find(int a, int d, int n) {
  for (;;) {
    if (isPrime(a))
      count++;
    if (count == n)
      return a;
    a += d;
  }
}
int main() {
  int a, d, n;
  for (;;) {
    cin >> a >> d >> n;
    if (!(a || d || n))
      break;
    count = 0;
    cout << find(a, d, n) << endl;
  }
  return 0;
}
int isPrime(int n) {
  int i;
  if (n == 2)
    return 1;
  if (n == 1 || n % 2 == 0)
    return 0;
  for (i = 3; i * i <= n; i += 2) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int isPrime(int);
int count;
int find(int a, int d, int n) {
  for (;;) {
    if (isPrime(a))
      count++;
    if (count == n)
      return a;
    a += d;
  }
}
int main() {
  int a, d, n;
  for (;;) {
    cin >> a >> d >> n;
    if (!(a || d || n))
      break;
    count = 0;
    cout << find(a, d, n) << endl;
  }

  return 0;
}
int isPrime(int n) {
  int i;
  if (n == 1)
    return 0;
  for (i = 2; i < n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
bool isprime(int n, int k = 2) {
  if (n == 1) {
    return false;
  }
  if (n < k * k) {
    return true;
  }
  if (n % k == 0) {
    return false;
  }
  return isprime(n, k + 1);
}
int main() {
  int a, d, n, c;
  while (true) {
    scanf("%d%d%d", &a, &d, &n);
    if (n == 0) {
      break;
    }
    c = 0;
    while (c < n) {
      if (isprime(a)) {
        c++;
      }
      a += d;
    }
    printf("%d\\n", a - d);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
bool isprime(int n, int k = 2) {
  if (n == 1) {
    return false;
  }
  if (n < k * k) {
    return true;
  }
  if (n % k == 0) {
    return false;
  }
  return isprime(n, k + 1);
}
int main() {
  int a, d, n, c;
  while (true) {
    scanf("%d%d%d", &n, &d, &a);
    if (n == 0) {
      break;
    }
    c = 0;
    while (c < n) {
      if (isprime(a)) {
        c++;
      }
      a += d;
    }
    printf("%d\\n", a - d);
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  bool a[1100000] = {0};
  a[1] = 1;
  for (int i = 2; i < 550001; i++) {
    if (a[i] == 1)
      continue;
    int j = 2 * i;
    while (j < 1100000) {
      a[j] = 1;
      j = j + i;
    }
  }
  int aa, d, n;
  while (cin >> aa >> d >> n && aa) {
    int k = aa;
    while (n > 0) {
      if (a[k] == 0) {
        n--;
      }
      k = k + d;
      //	cout<<k<<" "<<n<<endl;
    }

    cout << k - d << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  bool a[1100000] = {0};
  a[1] = 1;
  for (int i = 2; i < 550001; i++) {
    if (a[i] == 1)
      continue;
    int j = 2 * i;
    while (j < 1100000) {
      a[j] = 1;
      j = j + i;
    }
  }
  int aa, d, n;
  while (cin >> aa >> d >> n && aa) {
    int k = aa;
    while (n > 0) {
      if (a[k] == 0) {
        n--;
      }
      k = aa + d;
    }

    cout << k << endl;
  }

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

#include <cstdio>
#include <iostream>

using namespace std;
#define MAX 1000000

int main() {
  int i, n, a, b, cnt;
  bool prime[MAX];
  for (i = 0; i <= MAX; i++)
    prime[i] = true;
  prime[0] = prime[1] = false;

  for (i = 2; i < MAX; i++) {
    if (prime[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        prime[j] = false;
      }
    }
  }
  while (cin >> a >> b >> n, n != 0) {

    cnt = 0;
    for (i = a; i < MAX; i += b) {
      if (prime[i] == true)
        cnt++;
      if (cnt == n)
        break;
    }
    cout << i << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
#define MAX 1000000

int main() {
  int i, n, a, b, cnt;
  while (cin >> a >> b >> n, n != 0) {
    bool prime[MAX + 10];
    for (i = 0; i <= MAX; i++)
      prime[i] = true;
    prime[0] = prime[1] = false;

    for (i = 2; i <= MAX; i++) {
      if (prime[i]) {
        for (int j = i * 2; j <= MAX; j += i) {
          prime[j] = false;
        }
      }
    }
    cnt = 0;
    for (i = a; i <= MAX; i += b) {
      if (prime[i] == true)
        cnt++;
      if (cnt == n)
        break;
    }
    cout << i << endl;
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, d, n, cnt;
  bool b;
  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    cnt = 0;
    while (cnt != n) {
      b = true;
      if (a < 2 || a % 2 == 0)
        b = false;
      if (a == 2)
        b = true;
      for (int i = 3; i <= sqrt(a); i++) {
        if (a % i == 0) {
          b = false;
          break;
        }
      }
      if (b)
        cnt++;
      a += d;
    }
    cout << a - d << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, d, n, cnt;
  bool b;
  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    cnt = 0;
    b = true;
    while (cnt != n) {
      if (a < 2 || a % 2 == 0)
        b = false;
      if (a == 2)
        b = true;
      for (int i = 3; i <= sqrt(a); i++) {
        if (a % i == 0) {
          b = false;
          break;
        }
      }
      if (b)
        cnt++;
      a += d;
    }
    cout << a - d << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int arr[N];
// vector<int> prim;

void Erat() {
  for (int i = 0; i < N; i++) {
    arr[i] = 1;
  }
  for (int i = 2; i < sqrt(N); i++) {
    if (arr[i]) {
      for (int j = 0; i * (j + 2) < N; j++) {
        arr[i * (j + 2)] = 0;
      }
    }
  }
  /*
  for(int i = 2; i < N; i++){
          if(arr[i]){
                  //cout << i << endl;
      //prim.push_back(i);
          }
  }*/
}

int main() {
  Erat();
  arr[0] = 0;
  arr[1] = 0;
  while (1) {

    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 and d == 0 and n == 0)
      break;
    int cnt = 0;
    int A;

    int i = 0;
    while (cnt != n) {
      A = a + i * d;
      if (arr[A])
        cnt++;
      i++;
    }
    cout << A << endl;

  } // end
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 5000000;
int arr[N];
vector<int> prim;

void Erat() {
  for (int i = 0; i < N; i++) {
    arr[i] = 1;
  }
  for (int i = 2; i < sqrt(N); i++) {
    if (arr[i]) {
      for (int j = 0; i * (j + 2) < N; j++) {
        arr[i * (j + 2)] = 0;
      }
    }
  }

  for (int i = 2; i < N; i++) {
    if (arr[i]) {
      // cout << i << endl;
      prim.push_back(i);
    }
  }
}

int main() {
  Erat();
  while (1) {

    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 and d == 0 and n == 0)
      break;
    int cnt = 0;
    int i = 0;
    int A;

    while (cnt != n) {
      int idx = 0;
      A = a + i * d;

      while (A <= prim[idx]) {
        if (A == prim[idx]) {
          cnt++;
          break;
        }
        idx++;
      }

      i++;
    }
    cout << A << endl;

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

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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

int a, d, n;

bool is_prime[10000010];

int main() {
  cin.sync_with_stdio(false);
  rep(i, 10000001) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  repl(i, 2, 10000001) {
    if (is_prime[i]) {
      for (int j = i * 2; j <= 10000000; j += i)
        is_prime[j] = false;
    }
  }
  while (1) {
    cin >> a >> d >> n;
    if (a == 0)
      break;
    int cnt = 0;
    while (cnt < n) {
      if (is_prime[a])
        cnt++;
      a += d;
    }
    cout << a - d << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>

#define MAX_N 1000

using namespace std;

int a, d, n;
int prime[1000000];

bool judge(int n) {
  if (prime[n] == 0)
    return false;
  else
    return true;
}

void solve() {
  int i;
  int count = 0;
  for (i = a; i < 1000000; i += d) {
    if (judge(i))
      count++;
    if (count == n)
      break;
  }
  cout << i << endl;
}

int main() {
  for (int i = 0; i < 1000000; i++) {
    prime[i] = i;
  }
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i < 1000000;) {
    for (int j = i * 2; j < 1000000; j += i) {
      prime[j] = 0;
    }
    int k = i + 1;
    while (prime[k] == 0)
      k++;
    i = k;
  }
  while (1) {
    cin >> a >> d >> n;
    if (a == 0)
      break;
    solve();
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int main(void) {
  int prime[100000] = {};
  int pos = 2;
  prime[1] = 2;
  FOR(i, 3, 1000000) {
    FOR(t, 2, sqrt(i)) {
      if (i % t == 0) {
        break;
      }
      if (t + 1 > sqrt(i)) {
        prime[pos] = i;
        pos++;
      }
    }
  }

  while (1) {
    int a, d, n;
    int now = 1;
    bool flag = true;

    cin >> a >> d >> n;

    if (a == 0) {
      break;
    }
    for (int i = a; i <= 1000000; i += d) {
      FOR(t, now, pos - 1) {
        if (i == prime[t]) {
          if (n == 1) {
            cout << i << endl;
            now = t;
            flag = false;
            break;
          } else {
            n--;
            now = t;
          }
        }
        if (prime[t] > i) {
          now = t - 1;
          break;
        }
      }
      if (flag == false) {
        break;
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int main(void) {
  int prime[100000] = {};
  int pos = 2;
  prime[1] = 2;
  FOR(i, 3, 1000000) {
    FOR(t, 2, sqrt(i)) {
      if (i % t == 0) {
        break;
      }
      if (t + 1 > sqrt(i)) {
        prime[pos] = i;
        pos++;
      }
    }
  }

  while (1) {
    int a, d, n;
    bool flag = true;

    cin >> a >> d >> n;

    if (a == 0) {
      break;
    }
    for (int i = a; i <= 1000000; i += d) {
      FOR(t, 1, pos - 1) {
        if (i == prime[t]) {
          if (n == 1) {
            cout << i << endl;
            flag = false;
            break;
          } else {
            n--;
          }
        }
        if (prime[t] > i) {
          break;
        }
      }
      if (flag == false) {
        break;
      }
    }
  }
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int prime[1000000]; // prime[i] = 1 ... i is prime number.
  int a, d, n;
  int i, j;
  for (i = 1; i < 1000000; i++) {
    prime[i] = 1;
  }
  prime[1] = 0;
  for (i = 4; i < 1000000; i += 2) {
    prime[i] = 0;
  }
  for (i = 3; i < 1000; i += 2) {
    if (prime[i] == 0)
      continue;
    for (j = i * i; j < 1000000; j += i) {
      prime[j] = 0;
    }
  }

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

Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int prime[1000000]; // prime[i] = 1 ... i is prime number.
  int a, d, n;
  int i, j;
  prime[1] = 0;
  for (i = 4; i < 1000000; i += 2) {
    prime[i] = 0;
  }
  for (i = 3; i < 1000; i += 2) {
    if (prime[i] == 1)
      continue;
    for (j = i * i; j < 100000; j += i) {
      prime[j] = 0;
    }
  }

  while (1) {
    scanf("%d %d %d", &a, &d, &n);
    if (a == 0)
      break;
    i = 0;
    while (1) {
      if (prime[a + d * i]) {
        n--;
      }
      if (n == 0)
        break;
      i++;
    }
    printf("%d\\n", a + d * i);
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Memory Limit Exceeded



#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PA;
using namespace std;
#define MAX 999999
int main() {
  // ?´???°??????sqrt(max)??§??????
  vector<bool> check(MAX + 1);
  rep(i, MAX + 1) check[i] = true;
  vector<int> Primenumber(MAX + 1, 0); // Primearray
  int counter = 0;                     // Primearray counter;
  for (int i = 2; i < MAX + 1; i++) {
    if (check[i]) {
      for (int j = 2; i * j < MAX; j++)
        check[i * j] =
            false; //?´???°??????Primearray???????´??????????????????°?????¨???false???
      Primenumber[counter] = i;
      counter++;
    }
  }
  int a, d, n;
  while (cin >> a >> d >> n, a + d + n) {
    int count = 0;
    int ans = 0;
    while (true) {
      if (check[a] && a != 1)
        count++;
      if (count == n) {
        ans = a;
        break;
      }
      a += d;
    }
    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:



#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PA;
using namespace std;
#define MAX 99999999
int main() {
  // ?´???°??????sqrt(max)??§??????
  vector<bool> check(MAX + 1);
  rep(i, MAX + 1) check[i] = true;
  vector<int> Primenumber(MAX + 1, 0); // Primearray
  int counter = 0;                     // Primearray counter;
  for (int i = 2; i < MAX + 1; i++) {
    if (check[i]) {
      for (int j = 2; i * j < MAX; j++)
        check[i * j] =
            false; //?´???°??????Primearray???????´??????????????????°?????¨???false???
      Primenumber[counter] = i;
      counter++;
    }
  }
  int a, d, n;
  while (cin >> a >> d >> n, a + d + n) {
    int count = 0;
    int ans = 0;
    while (true) {
      if (check[a] && a != 1)
        count++;
      if (count == n) {
        ans = a;
        break;
      }
      a += d;
    }
    cout << ans << endl;
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main(void) {
  bool prime[1000000];
  for (int i = 0; i < 1000000; i++) {
    prime[i] = true;
  }
  prime[0] = prime[1] = false;

  for (int i = 1; i < sqrt(1000000); i++) {
    if (prime[i]) {
      for (int j = 0; i * (j + 2) <= 1000000; j++) {
        prime[i * (j + 2)] = false;
      }
    }
  }
  vector<int> p;
  p.push_back(-1);
  for (int i = 2; i < 1000000; i++) {
    if (prime[i]) {
      p.push_back(i);
    }
  }

  while (1) {
    int a, d, n;
    scanf("%d %d %d", &a, &d, &n);
    if (a == 0 && d == 0 && n == 0)
      break;

    int count = 0;
    for (int i = a; i < 1000000; i += d) {
      if (prime[i]) {
        count++;
        if (n == count) {
          printf("%d\\n", i);
        }
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main(void) {
  while (1) {
    int a, d, n;
    scanf("%d %d %d", &a, &d, &n);
    if (a == 0 && d == 0 && n == 0)
      break;

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

    for (int i = 1; i < sqrt(1000000); i++) {
      if (prime[i]) {
        for (int j = 0; i * (j + 2) <= 1000000; j++) {
          prime[i * (j + 2)] = false;
        }
      }
    }
    vector<int> p;
    p.push_back(-1);
    for (int i = 2; i < 1000000; i++) {
      if (prime[i]) {
        p.push_back(i);
      }
    }

    int count = 0;
    for (int i = a; i < 1000000; i += d) {
      if (prime[i]) {
        count++;
        if (n == count) {
          printf("%d\\n", i);
        }
      }
    }
  }
  return 0;
}