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

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

vector<int> era(int x) {
  int search[x];
  int len = 0;
  vector<int> primes;
  search[0] = search[1] = 0;
  for (int i = 2; i < x; i++)
    search[i] = 1;
  double root_x = sqrt(x);
  for (int i = 0;; i++) {
    int num = search[i];
    if (num == 1) {
      if (root_x <= i)
        break;
      else {
        primes.push_back(i);
        len++;
        for (int j = i; j < x; j += i)
          search[j] = 0;
      }
    }
  }
  for (int i = 0; i < x; i++) {
    if (search[i] == 1) {
      primes.push_back(i);
      len++;
      search[i] = 0;
    }
  }
  return primes;
}

int main(void) {

  vector<int> primes = era(1000000);

  while (1) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    int count_primes = 0;
    int primes_now = 0;
    for (int i = a; i < 1000000; i += d) {
      for (int j = primes_now; j < primes.size(); j++) {
        if (primes[j] == i) {
          count_primes++;
          primes_now = j;
          break;
        } else if (primes[j] > i) {
          primes_now = j;
          break;
        }
      }
      if (count_primes == n) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

bool is_prime(int x) {
  if (x < 2)
    return false;
  if (x == 2)
    return true;
  if (x % 2 == 0)
    return false;
  for (int i = x / 2; 2 < i; i--) {
    if (x % i == 0)
      return false;
  }
  return true;
}

int main(void) {

  while (1) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    int count_primes = 0;
    int primes_now = 0;
    for (int i = a; i < 1000000; i += d) {
      if (is_prime(i)) {
        count_primes++;
        if (count_primes == n) {
          cout << i << endl;
          break;
        }
      }
    }
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

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

  f[1] = false;
  while (1) {
    int a, b, n;
    scanf("%d%d%d", &a, &b, &n);
    if (a == 0 && b == 0 && n == 0)
      break;
    int c = 0;
    // for(int i=0;c<n;i++){
    int i = 0;
    while (c != n) {
      if (f[a + b * i] == true)
        c++;
      i++;
    }
    printf("%d\\n", a + b * (i - 1));
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {

  int x, y, z;
  int cou = 0;
  while (1) {
    cou = 0;
    scanf("%d", &x);
    scanf("%d", &y);
    scanf("%d", &z);
    if (x == 0 && y == 0 && z == 0)
      break;

    int k, i;
    int yakusuu = 0;
    i = x;

    while (1) {
      yakusuu = 0;
      if (3 < i && i % 2 == 1) {
        for (int j = 1; j <= i; j++) {

          if (i % j == 0)
            yakusuu++;
        }

        if (yakusuu == 2)
          cou++;

      } else if (i == 2)
        cou++;

      if (cou == z)
        break;
      i += y;
    }

    printf("%d\\n", i);
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  bool prime[2000000];
  prime[1] = false;
  for (int i = 2; i <= 1000000; i++) {
    prime[i] = true;
  }
  for (int i = 2; i * i < 1000001; i++) {
    if (prime[i]) {
      for (int j = 2; i * j < 1000001; j++) {
        prime[i * j] = false;
      }
    }
  }

  while (true) {
    int a, d, n;
    cin >> a >> d >> n;
    if (n == 0)
      break;
    int count = 0, idx = 0;
    while (count < n) {
      if (prime[a + d * idx])
        count++;
      idx++;
    }
    cout << a + d * (idx - 1) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  bool prime[1000001];
  for (int i = 1; i < 1000001; i++) {
    prime[i] = is_prime(i);
  }
  while (true) {
    int a, d, n;
    cin >> a >> d >> n;
    if (n == 0)
      break;
    int count = 0, idx = 0;
    while (count < n) {
      if (prime[a + d * idx])
        count++;
      idx++;
    }
    cout << a + d * (idx - 1) << endl;
  }
}
Problem p00722 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define pb push_back

#define N 1000000

#define int long long
int arr[N];

void eratosthenes() {
  rep(i, N) { 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;
      }
    }
  }

  arr[0] = 0;
  arr[1] = 0;
}

signed main() {

  eratosthenes();

  // for(int i=0;i<100;i++){
  // 	cout<<i<<" "<<arr[i]<<endl;
  // }

  int count;
  int a, d, n;
  while (1) {

    cin >> a >> d >> n;

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

    count = 0;

    for (int i = a; i < 1000000; i += d) {
      // if(count>220)break;

      if (arr[i] == 1) {

        // cout<<arr[i]<<":"<<count<<":"<<i<<endl;
        if (count == n - 1) {
          cout << i << endl;
          break;
        }
        count++;
      }
    }

    // rep(i,100){
    // 	cout<<i<<" "<<v[i]<<endl;

    // }

    // cout<<v[n-1]<<endl;

    // rep(i,100){
    // 	cout<<v[i]<<endl;
    // }
    // cout<<v[n-1]<<endl;
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define pb push_back

#define N 100000000

#define int long long
int arr[N];

void eratosthenes() {
  rep(i, N) { 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;
      }
    }
  }

  arr[0] = 0;
  arr[1] = 0;
}

signed main() {

  eratosthenes();

  // for(int i=0;i<100;i++){
  // 	cout<<i<<" "<<arr[i]<<endl;
  // }

  int count;
  int a, d, n;
  while (1) {

    cin >> a >> d >> n;

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

    count = 0;

    for (int i = a; i < 100000000; i += d) {
      // if(count>220)break;

      if (arr[i] == 1) {

        // cout<<arr[i]<<":"<<count<<":"<<i<<endl;
        if (count == n - 1) {
          cout << i << endl;
          break;
        }
        count++;
      }
    }

    // rep(i,100){
    // 	cout<<i<<" "<<v[i]<<endl;

    // }

    // cout<<v[n-1]<<endl;

    // rep(i,100){
    // 	cout<<v[i]<<endl;
    // }
    // cout<<v[n-1]<<endl;
  }
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i <= n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int Prime_n(int a, int d, int n) {

  int cnt = 0;
  bool isPrime;

  while (1) {

    isPrime = true;

    if (a == 1) {
      isPrime = false;
    } else {
      REP(i, 2, sqrt(a)) {
        if (a % i == 0) {
          isPrime = false;
          break;
        }
      }
    }

    if (isPrime)
      cnt++;

    if (cnt == n)
      return a;

    a += d;
  }
}
int main() {

  int a, d, n;

  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    cout << Prime_n(a, d, n) << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = 0; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;

typedef struct {

  int x, y;

} xy;

int main() {

  int N;
  int num_block, direction;
  int x_max, y_max, x_min, y_min;
  xy data[200];

  data[0].x = 1, data[0].y = 1;

  while (1) {

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

    x_max = 1, y_max = 1;
    x_min = 0, y_min = 0;

    rep(i, N - 1) {
      cin >> num_block >> direction;
      if (direction == 0) {
        data[i + 1].x = data[num_block].x - 1;
        data[i + 1].y = data[num_block].y;
      } else if (direction == 1) {
        data[i + 1].x = data[num_block].x;
        data[i + 1].y = data[num_block].y - 1;
      } else if (direction == 2) {
        data[i + 1].x = data[num_block].x + 1;
        data[i + 1].y = data[num_block].y;
      } else {
        data[i + 1].x = data[num_block].x;
        data[i + 1].y = data[num_block].y + 1;
      }
      if (data[i + 1].x > x_max) {
        x_max = data[i + 1].x;
      } else if (data[i + 1].x - 1 < x_min) {
        x_min = data[i + 1].x - 1;
      } else if (data[i + 1].y > y_max) {
        y_max = data[i + 1].y;
      } else if (data[i + 1].y - 1 < y_min) {
        y_min = data[i + 1].y - 1;
      }
    }

    // cout <<x_max<<" "<<x_min<<endl;
    // cout <<y_max<<" "<<y_min<<endl;

    cout << x_max - x_min << " " << y_max - y_min << endl;
  }

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr << #x << ": " << x << endl;

#define fi first
#define se second

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

bool SO[1001000];

void erast(int n) {
  memset(SO, true, sizeof(SO));
  SO[1] = false;
  SO[0] = false;
  REP(i, 2, sqrt(n)) {
    if (SO[i]) {
      REP(j, 2, n) {
        if (i * j >= 1000100)
          break;
        SO[i * j] = false;
      }
    }
  }
}

int main() {
  //    ifstream in("input.txt");
  //    cin.rdbuf(in.rdbuf());
  erast(1000100);
  int a, d, n;
  while (cin >> a >> d >> n, a + d + n) {
    rep(i, n) {
      while (!SO[a])
        a += d;
      a += d;
    }
    cout << a - d << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr << #x << ": " << x << endl;

#define fi first
#define se second

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

bool SO[1000110];

void erast(int n) {
  memset(SO, -1, sizeof(SO));
  SO[1] = false;
  SO[0] = false;
  REP(i, 2, sqrt(n)) {
    if (SO[i]) {
      REP(j, 2, n) {
        if (i * j >= 1000100)
          break;
        SO[i * j] = false;
      }
    }
  }
}

int main() {
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  erast(1000100);
  int a, d, n;
  while (cin >> a >> d >> n, a + d + n) {
    rep(i, n) {
      while (!SO[a])
        a += d;
      a += d;
    }
    cout << a - d << endl;
  }

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

#include <algorithm>
#include <fstream>
#include <iostream>
#include <list>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define LL long long
using namespace std;

#define int LL

bool func(int x) {
  if (x < 2)
    return false;

  for (int i = 2; i * i <= x; ++i) {
    if (x % i == 0)
      return false;
  }

  return true;
}

signed main() {
  // ifstream cin("Ain.txt");
  // ofstream cout("Aout.txt");

  int a, d, n;

  do {
    cin >> a >> d >> n;

    if (!(a && d && n))
      break;

    a -= d;

    while (n) {
      a += d;
      if (func(a))
        n--;
    }
    cout << a << endl;
  } while (!(a && d && n));
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iostream>
#include <list>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define LL long long
using namespace std;

#define int LL

bool func(int x) {
  if (x < 2)
    return false;

  for (int i = 2; i * i <= x; ++i) {
    if (x % i == 0)
      return false;
  }

  return true;
}

signed main() {
  // ifstream cin("Ain.txt");
  // ofstream cout("Aout.txt");

  int a, d, n;

  do {
    cin >> a >> d >> n;

    a -= d;

    while (n) {
      a += d;
      if (func(a))
        n--;
    }
    cout << a << endl;
  } while (!(a && d && n));
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  static int p[10 * 100 * 1000] = {};
  int index = 0;
  int a, d, n;
  while (cin >> a >> d >> n && a != 0 && d != 0 && n != 0) {
    index = 0;
    for (int i = a; i < 1000000; i += d) {
      bool f = true;
      if (i < 2)
        continue;
      for (int j = 2; j * j <= i; j++) {
        if (i % j == 0) {
          f = false;
          break;
        }
      }

      if (f) {
        p[index] = i;
        index++;
        if (index >= n)
          break;
      }
    }
    cout << p[n - 1] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  static int p[10 * 100 * 1000] = {};
  int index = 0;
  int a, d, n;
  while (cin >> a >> d >> n && a != 0 && d != 0 && n != 0) {
    index = 0;
    for (int i = a; i < 1000000; i += d) {
      bool f = true;
      if (i < 2)
        continue;
      for (int j = 2; j * j <= i; j++) {
        if (i % j == 0) {
          f = false;
          break;
        }
      }

      if (f) {
        p[index] = i;
        index++;
      }
    }

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

// suhan lee,saitama university

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define repn(i, n) for (int i = 0; i < n; i++)
#define EACH(t, i, c) for (t::iterator i = (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define pf push_front

int main() {
  int a, d, n;
  vi table(1000000, 1);
  table[1] = 0;
  table[0] = 0;
  for (int i = 2; i < 1000000; i++) {
    if (table[i] == 0)
      continue;
    for (int j = i * 2; j < 1000000; j += i) {
      table[j] = 0;
    }
  }
  while (true) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    while (1) {
      if (table[a] == 1)
        n--;
      if (n == 0)
        break;
      a += d;
    }
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int main() {
  using namespace std;
  int a, d, n, i, tmp;

  while (1) {
    cin >> a >> d >> n;
    tmp = a;
    i = 0;
    if (a == 0 && d == 0 && n == 0)
      return 0;
    while (1) {
      for (int j = 2; j < tmp / 2; j++) {
        //  cout<<"test  "<<j<<"  "<<tmp<<endl;
        if (tmp % j == 0) {

          j = 1;
          tmp += d;
          continue;
        }
      }
      i++;
      if (i == n) {
        cout << tmp << endl;
        break;
      }
      tmp += d;
    }
  }
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

#define max 1000000
int main() {
  bool prime[max] = {1, 1, 0};
  range(i, 2, max) {
    if (!prime[i]) {
      for (int j = i + i; j <= max; j += i) {
        prime[j] = 1;
      }
    }
  }
  int a, b, n;
  while (cin >> a >> b >> n, a || b || n) {
    rep(i, max) {
      if (prime[a + b * i] == 0) {
        n--;
      }
      if (!n) {
        cout << a + b * i << endl;
        break;
      }
    }
  }
}

Error: WA

Fixed submission:

#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int grave = 0;

void solve(int p[], int num, char inp) {
  if (inp == 'S') {
    grave += p[num];
    grave++;
    p[num] = 0;
  } else if (inp == 'L') {
    p[num] += grave;
    p[num]++;
    grave = 0;
  } else if (inp == 'M') {
    p[num]++;
  }
  return;
}

int main() {
  int n;
  while (cin >> n, n) {
    int p[11] = {0};
    grave = 0;
    string str;
    cin >> str;
    rep(i, str.size()) { solve(p, i % n, str[i]); }
    rep(i, n) { cout << p[i] << ' '; }
    cout << grave << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

bool isPrime(int x) {
  if (x == 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  if (x % 2 == 0) {
    return false;
  }

  for (int i = 3; i * i <= x; i += 2) {
    if (x % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  while (1) {
    int a, d, n;
    cin >> a >> d >> n;

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

bool isPrime(int x) {
  if (x == 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  if (x % 2 == 0) {
    return false;
  }

  for (int i = 3; i < x; i += 2) {
    if (x % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  while (1) {
    int a, d, n;
    cin >> a >> d >> n;

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

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

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

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

using namespace std;
int num[1000001];

bool sosu(int n) {
  if (num[n] == -1)
    return false;
  if (num[n] == 1)
    return true;

  int sqr = sqrt(n);
  for (int i = 2; i <= sqr; i++) {
    if (n % i == 0) {
      num[n] = -1;
      return false;
    }
  }
  num[n] = 1;
  return true;
}

int main() {
  int a, d, n;
  num[1] = -1;
  while (cin >> a >> d >> n, a || d || n) {
    int counter = 0;
    for (int i = a;; i = i + d) {
      if (sosu(i))
        counter++;
      if (counter == n) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;
int num[1000001];

bool sosu(int n) {
  if (num[n] == -1)
    return false;
  if (num[n] == 1)
    return true;

  for (int i = 2; i <= n / 2; i++) {
    if (n % i == 0) {
      num[n] = -1;
      return false;
    }
  }
  num[n] = 1;
  return true;
}

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

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

#define MAX 1000000

bool v[MAX + 1];

void set(int n) {
  for (int i = n * 2; i < MAX; i += n) {
    v[i] = true;
  }
}

int main() {
  int a, d, n;
  v[1] = true;
  for (int i = 2; i < MAX; i++) {
    if (v[i])
      continue;
    set(i);
  }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, d, n;
  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0) {
      break;
    }
    int count = 0;
    int ans;
    for (int i = 0; count < n; i++) {
      ans = a + d * i;
      //?´???°??????
      int flg = 0;
      if (ans % 2 == 0) {
        flg = 1;
      } else {
        for (int j = 3; j < ans; j += 2) {
          if (ans % j == 0) {
            flg = 1;
            break;
          }
        }
      }
      if (flg == 0) {
        count++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

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

  while (cin >> a >> b >> n && n) {
    int count = 0, flag = 0;
    for (int i = a; i <= 1000000; i += b) {
      for (int j = 2; j <= sqrt(i); j++) {
        if (i % j == 0 && i != j) {
          flag++;
          break;
        }
      }
      if (!flag && i >= 2)
        count++;
      if (count == n) {
        cout << i << endl;
        break;
      }
      flag = 0;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  while (cin >> a >> b >> n && n) {
    int count = 0, flag = 0;
    for (int i = a; i < 1000000; i += b) {
      for (int j = 2; j < i; j++) {
        if (i % j == 0 && i != j) {
          flag++;
          break;
        }
      }
      if (!flag && i >= 2)
        count++;
      if (count == n) {
        cout << i << endl;
        break;
      }
      flag = 0;
    }
  }
}