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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

ll m, a, b;
vector<int> prime;
bool is_prime[100005];

void solve() {
  P ans;
  ll maxi = 0;
  rep(i, prime.size()) for (int j = i; j < prime.size(); j++) {
    ll p = prime[i];
    ll q = prime[j];
    if (m < p * q)
      break;
    if (m >= p * q && 1.0 * a / b <= 1.0 * p / q && 1.0 * p / q <= 1.0) {
      if (maxi < p * q) {
        ans = P(p, q);
        maxi = p * q;
      }
    }
  }
  cout << ans.fr << " " << ans.sc << endl;
}

void init() {
  rep(i, 100005) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100005; i++) {
    if (is_prime[i])
      for (int j = i + i; j < 100005; j += i)
        is_prime[j] = false;
  }

  rep(i, 100005) if (is_prime[i]) prime.pb(i);
}

int main() {
  init();
  while (cin >> m >> a >> b) {
    if (m + a + b == 0)
      break;
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

ll m, a, b;
vector<int> prime;
bool is_prime[100005];

void solve() {
  P ans;
  ll maxi = 0;
  rep(i, prime.size()) rep(j, prime.size()) {
    ll p = prime[i];
    ll q = prime[j];
    if (m >= p * q && 1.0 * a / b <= 1.0 * p / q && 1.0 * p / q <= 1.0) {
      if (maxi < p * q) {
        ans = P(p, q);
        maxi = p * q;
      }
    }
  }
  cout << ans.fr << " " << ans.sc << endl;
}

void init() {
  rep(i, 100005) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100005; i++) {
    if (is_prime[i])
      for (int j = i + i; j < 100005; j += i)
        is_prime[j] = false;
  }

  rep(i, 100005) if (is_prime[i]) prime.pb(i);
}

int main() {
  init();
  while (cin >> m >> a >> b) {
    if (m + a + b == 0)
      break;
    solve();
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int m, a, b, i, j;
  for (i = 2; i < 50000; i++) {
    bool ok = 1;
    for (j = 0; j < v.size(); j++)
      if (i % v[j] == 0)
        ok = 0;
    if (ok)
      v.push_back(i);
  }
  while (cin >> m >> a >> b && m) {
    int p = 0, q = 0;
    for (i = 0; i < v.size(); i++) {
      for (j = i; j < v.size(); j++) {
        if (v[i] * v[j] > m)
          break;
        if (v[j] <= b * v[i] / a && p * q < v[i] * v[j])
          p = v[i], q = v[j];
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int m, a, b, i, j;
  for (i = 2; i < 50000; i++) {
    bool ok = 1;
    for (j = 0; j < v.size(); j++)
      if (!i % v[j])
        ok = 0;
    if (ok)
      v.push_back(i);
  }
  while (cin >> m >> a >> b && m) {
    int p = 0, q = 0;
    for (i = 0; i < v.size(); i++) {
      for (j = i; j < v.size(); j++) {
        if (v[i] * v[j] > m)
          break;
        if (v[j] <= b * v[i] / a && p * q < v[i] * v[j])
          p = v[i], q = v[j];
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  vector<long long> p;
  for (int i = 2; i <= 100000; i++) {
    int f = true;
    for (int j = 2; j * j <= i; j++)
      if (i % j == 0) {
        f = 0;
        break;
      }
    if (f) {
      p.push_back(i);
    }
  }
  long long m, a, b;
  while (cin >> m >> a >> b && m) {
    long long ans = 0;
    long long A = 0;

    for (int i = 0; i < p.size(); i++) {
      // cout << i << " " << m << " " << p[i] << endl;
      int j = upper_bound(p.begin() + i, p.end(), m / p[i]) - p.begin();
      j = upper_bound(p.begin() + i, p.begin() + j, p[i] * b / a) - p.begin() -
          1;
      if (j < i)
        continue;
      // cout << p[i] << " " << p[j] << endl;
      // cout << "OK" << p[i] << " " << p[j] << " " << 1.0 * p[i] / p[j] <<
      // endl;
      if (p[i] * p[j] > m)
        continue;
      if (p[i] * p[j] <= m && a * p[j] <= p[i] * b) {
        if (p[i] * p[j] > ans) {
          ans = p[i] * p[j];
          A = p[i];
        }
      }
    }
    cout << A << " " << ans / A << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  vector<int> p;
  for (int i = 2; i <= 100000; i++) {
    int f = true;
    for (int j = 2; j * j <= i; j++)
      if (i % j == 0) {
        f = 0;
        break;
      }
    if (f) {
      p.push_back(i);
    }
  }
  long long m, a, b;
  while (cin >> m >> a >> b && m) {
    long long ans = 0;
    long long A = 0;
    for (int i = 0; i < p.size(); i++) {
      for (int j = i; j < p.size(); j++) {
        if (p[i] * p[j] <= m && a * p[j] <= p[i] * b) {
          if (p[i] * p[j] > ans) {
            ans = p[i] * p[j];
            A = p[i];
          }
        } else if (p[i] * p[j] > m) {
          break;
        }
      }
    }
    cout << A << " " << ans / A << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP((i), 0, (n))
#define REP(i, a, n) for (int i = (a); i < (n); i++)

int N = 100000;
bool is_prime[100000];
void set_prime() {
  memset(is_prime, true, N);
  is_prime[0] = is_prime[1] = false;
  REP(i, 2, sqrt(N)) {
    if (is_prime[i]) {
      for (int j = 0; i * (j + 2) < N; j++) {
        is_prime[i * (j + 2)] = false;
      }
    }
  }
}

int main() {
  int m, a, b;
  set_prime();
  while (cin >> m >> a >> b, m + a + b) {
    int c = 0, p, q, pp, qq;
    for (p = 2; p < m; p++) {
      if (!is_prime[p] || m / p < 2)
        continue;
      for (q = m / p; q >= p; q--) {
        if (!is_prime[q] || a * q > b * p)
          continue;
        if (p * q > c) {
          c = p * q;
          pp = p;
          qq = q;
        };
      }
      if ((double)p / q < (double)a / b)
        continue;
    }
    cout << pp << " " << qq << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP((i), 0, (n))
#define REP(i, a, n) for (int i = (a); i < (n); i++)

int N = 100000;
bool is_prime[100000];
void set_prime() {
  memset(is_prime, true, N);
  is_prime[0] = is_prime[1] = false;
  REP(i, 2, sqrt(N)) {
    if (is_prime[i]) {
      for (int j = 0; i * (j + 2) < N; j++) {
        is_prime[i * (j + 2)] = false;
      }
    }
  }
}

int main() {
  int m, a, b;
  set_prime();
  while (cin >> m >> a >> b, m + a + b) {
    int c = 0, pp, qq;
    rep(q, m) {
      if (!is_prime[q])
        continue;
      REP(p, a * q / b, q + 1) {
        if (!is_prime[p])
          continue;
        if (p * q > m)
          break;
        if (p * q > c) {
          c = p * q;
          pp = p;
          qq = q;
        }
      }
    }
    cout << pp << " " << qq << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int, int> pii;

signed main(void) {
  int i, j;
  int m, a, b;
  vi p(100005, true);
  for (i = 2; i < 100005; i++)
    if (p[i])
      for (j = 2; i * j < 100005; j++)
        p[i * j] = false;
  vi prime;
  loop(i, 2, 100005) if (p[i]) prime.push_back(i);
  while (1) {
    cin >> m >> a >> b;
    if (m + a + b == 0)
      break;
    int g = __gcd(a, b);
    a /= g;
    b /= g;
    int x, y;
    int ans = 0;
    rep(i, prime.size())
        loop(j, i, prime.size()) if (prime[i] * prime[j] > m ||
                                     b * prime[i] < a * prime[j]) break;
    else if (prime[i] * prime[j] > ans) {
      ans = prime[i] * prime[j];
      x = prime[i];
      y = prime[j];
      //	cout<<x<<" "<<y<<" "<<ans<<endl;
    }
    cout << x << " " << y << endl;
  }
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int, int> pii;

signed main(void) {
  int i, j;
  int m, a, b;
  vi p(100005, true);
  for (i = 2; i < 100005; i++)
    if (p[i])
      for (j = 2; i * j < 100005; j++)
        p[i * j] = false;
  vi prime;
  loop(i, 2, 100005) if (p[i]) prime.push_back(i);
  while (1) {
    cin >> m >> a >> b;
    if (m + a + b == 0)
      break;
    int g = __gcd(a, b);
    a /= g;
    b /= g;
    int x, y;
    int ans = 0;
    rep(i, prime.size())
        loop(j, i, prime.size()) if (prime[i] * prime[j] <= m &&
                                     prime[i] * prime[j] > ans &&
                                     b * prime[i] >= a * prime[j]) {
      ans = prime[i] * prime[j];
      x = prime[i];
      y = prime[j];
      //	cout<<x<<" "<<y<<" "<<ans<<endl;
    }
    cout << x << " " << y << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int z[100001] = {0};
  for (int i = 2; i < 100000; i++) {
    if (i % 2 == 0 && i != 2) {
      goto end;
    } else if (i % 3 == 0 && i != 3) {
      goto end;
    } else {
      for (int j = 1; j < pow(i, 0.5) / 6 + 3; j++) {
        if (i % (6 * j - 1) == 0 && i != 6 * j - 1) {
          goto end;
        }
        if (i % (6 * j + 1) == 0 && i != 6 * j + 1) {
          goto end;
        }
      }
    }
    z[i] = 1;
  end:;
  }
  int m;
  double a, b;
  while (cin >> m >> a >> b) {
    if (m == 0 && a == 0 && b == 0)
      break;
    int s = pow(m, 0.5), p, q;
    double ab, pqm = 0;
    ab = a / b;
    while (s * s / ab >= pqm || s > 1) {
      if (z[s] == 1) {
        double qq = min(s / ab, 100000.00);
        for (int i = s; i <= qq; i++) {
          if (z[i] == 1) {
            double pq = s * i;
            if (pq > pqm && pq <= m) {
              p = s;
              q = i;
              pqm = max(pq, pqm);
            }
          }
        }
      }
      s--;
    }
    cout << p << " " << q << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int z[100001] = {0};
  for (int i = 2; i < 100000; i++) {
    if (i % 2 == 0 && i != 2) {
      goto end;
    } else if (i % 3 == 0 && i != 3) {
      goto end;
    } else {
      for (int j = 1; j < pow(i, 0.5) / 6 + 3; j++) {
        if (i % (6 * j - 1) == 0 && i != 6 * j - 1) {
          goto end;
        }
        if (i % (6 * j + 1) == 0 && i != 6 * j + 1) {
          goto end;
        }
      }
    }
    z[i] = 1;
  end:;
  }
  int m;
  double a, b;
  while (cin >> m >> a >> b) {
    if (m == 0 && a == 0 && b == 0)
      break;
    int s = pow(m, 0.5), p, q;
    double ab, pqm = 0;
    ab = a / b;
    while (s * s / ab >= pqm) {
      if (z[s] == 1) {
        double qq = s / ab;
        for (int i = s; i <= qq; i++) {
          if (z[i] == 1) {
            double pq = s * i;
            if (pq > pqm && pq <= m) {
              p = s;
              q = i;
              pqm = max(pq, pqm);
            }
          }
        }
      }
      s--;
    }
    cout << p << " " << q << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

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

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

  vector<ll> ps;
  for (int i = 2; i <= 100000; i++) {
    if (isPrime(i))
      ps.push_back(i);
  }

  ll m, a, b;
  while (cin >> m >> a >> b, m) {
    ll mx = -1, mp = -1, mq = -1;
    for (int i = 0; i < ps.size(); i++) {
      for (int j = i; j < ps.size(); j++) {
        ll p = ps[i], q = ps[j];
        if (p * q <= m && a * q <= b * p) {
          if (mx < p * q) {
            mx = p * q;
            mp = p;
            mq = q;
          }
        } else
          break;
      }
    }
    cout << mp << " " << mq << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

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

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

  vector<ll> ps;
  for (int i = 2; i <= 100000; i++) {
    if (isPrime(i))
      ps.push_back(i);
  }

  ll m, a, b;
  while (cin >> m >> a >> b, m) {
    ll mx = -1, mp = -1, mq = -1;
    for (int i = 0; i < ps.size(); i++) {
      for (int j = i; j < ps.size(); j++) {
        ll p = ps[i], q = ps[j];
        if (p * q <= m && a * q <= b * p) {
          if (mx < p * q) {
            mx = p * q;
            mp = p;
            mq = q;
          }
        }
      }
    }
    cout << mp << " " << mq << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100001
int prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1];

// n以下の素数の数を返す
int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
  return p;
}

int main() {
  int m, a, b;
  sieve(100000);
  while (cin >> m >> a >> b, m) {
    int ma = 0;
    int x, y;
    for (int i = 0;; i++) {
      if (prime[i] * prime[i] > m)
        break;
      for (int j = i;; j++) {
        if (prime[i] * prime[j] > m)
          break;
        if ((double)prime[i] / prime[j] < (double)a / b)
          continue;
        if (prime[i] * prime[j] > ma) {
          ma = prime[i] * prime[j];
          x = prime[i];
          y = prime[j];
        }
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
int prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1];

// n以下の素数の数を返す
int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
  return p;
}

int main() {
  int m, a, b;
  sieve(10000);
  while (cin >> m >> a >> b, m) {
    int ma = 0;
    int x, y;
    for (int i = 0;; i++) {
      if (prime[i] * prime[i] > m)
        break;
      for (int j = i;; j++) {
        if (prime[i] * prime[j] > m)
          break;
        if ((double)prime[i] / prime[j] < (double)a / b)
          continue;
        if (prime[i] * prime[j] > ma) {
          ma = prime[i] * prime[j];
          x = prime[i];
          y = prime[j];
        }
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1 << 28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vi v;
void sieve() {
  bool prime[50000];
  fill(prime, prime + 50000, true);
  prime[0] = prime[1] = false;
  REP(i, 50000)
  if (prime[i])
    for (int j = i * 2; j < 50000; j += i)
      prime[j] = false;
  REP(i, 50000)
  if (prime[i])
    v.pb(i);
  return;
}

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

  sieve();
  int m, a, b;
  while (cin >> m >> a >> b, m | a | b) {
    ll max = 0;
    int p, q;
    REP(i, v.size()) {
      REP(j, v.size()) {
        if (v[i] * v[j] > m)
          break;
        if (v[i] * v[j] <= m && (double)a / b <= (double)v[i] / v[j] &&
            (double)v[i] / v[j] <= 1 && v[i] * v[j] > max) {
          max = v[i] * v[j];
          p = v[i];
          q = v[j];
        }
      }
    }
    cout << p << ' ' << q << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1 << 28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vi v;
void sieve() {
  bool prime[100000];
  fill(prime, prime + 100000, true);
  prime[0] = prime[1] = false;
  REP(i, 100000)
  if (prime[i])
    for (int j = i * 2; j < 100000; j += i)
      prime[j] = false;
  REP(i, 100000)
  if (prime[i])
    v.pb(i);
  return;
}

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

  sieve();
  int m, a, b;
  while (cin >> m >> a >> b, m | a | b) {
    ll max = 0;
    int p, q;
    REP(i, v.size()) {
      REP(j, v.size()) {
        if (v[i] * v[j] <= m && (double)a / b <= (double)v[i] / v[j] &&
            (double)v[i] / v[j] <= 1 && v[i] * v[j] > max) {
          max = v[i] * v[j];
          p = v[i];
          q = v[j];
        }
      }
    }
    cout << p << ' ' << q << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct data {
  int pq, p, q;
};

const int MAX_N = 50000;
bool prime[MAX_N + 1];

void sieve() {
  fill(prime, prime + MAX_N + 1, true);
  prime[0] = prime[1] = false;
  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 main() {
  sieve();
  while (1) {
    int m, a, b;
    cin >> m >> a >> b;
    if (m == 0 && a == 0 && b == 0)
      break;
    struct data ans;
    ans.pq = 0;
    for (int i = 2; i <= MAX_N; i++) {
      if (prime[i]) {
        for (int j = i; j <= MAX_N; j++) {
          if (prime[j]) {
            int y = i * j;
            if (y > m)
              break;
            if (y < ans.pq)
              continue;
            if (a * j <= b * i) {
              ans.pq = y;
              ans.p = i;
              ans.q = j;
            }
          }
        }
      }
    }
    cout << ans.p << " " << ans.q << endl;
  }
}

Error: TLE

Fixed submission:

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

struct data {
  int pq, p, q;
};

bool comp(const data &a, const data &b) { return a.pq > b.pq; }

const int MAX_N = 50000;
bool prime[MAX_N + 1];

void sieve() {
  fill(prime, prime + MAX_N + 1, true);
  prime[0] = prime[1] = false;
  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 main() {
  sieve();
  while (1) {
    int m, a, b;
    cin >> m >> a >> b;
    if (m == 0 && a == 0 && b == 0)
      break;
    vector<data> v;
    for (int i = 2; i <= MAX_N; i++) {
      if (prime[i]) {
        for (int j = i; j <= MAX_N; j++) {
          if (prime[j]) {
            int y = i * j;
            if (y > m)
              break;
            if (a * j <= b * i) {
              struct data d;
              d.pq = y;
              d.p = i;
              d.q = j;
              v.push_back(d);
            }
          }
        }
      }
    }
    sort(v.begin(), v.end(), comp);
    cout << v[0].p << " " << v[0].q << endl;
  }
}