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

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

template <class t> void vin(vector<t> &v, int n) {
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
}

const int MAX_N = 100001;

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

void eratos(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;
    }
  }
}

int main() {
  eratos(MAX_N);
  double m, a, b;
  while (cin >> m >> a >> b and (m or a or b)) {
    double best = 0, P = 0, Q = 0;
    for (double p = 2; p <= m; ++p) {
      if (!is_prime[(int)p])
        continue;
      int qq = m / p;
      for (double q = qq; q >= 2; --q) {
        if (is_prime[(int)q]) {
          if (a / b > p / q or p / q > 1.0)
            continue;
          if (best < p * q) {
            best = p * q;
            P = p;
            Q = q;
          }
          break;
        }
      }
    }
    cout << P << ' ' << Q << 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))
using ll = long long;
using P = pair<ll, ll>;
using namespace std;

template <class t> void vin(vector<t> &v, int n) {
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
}

const int MAX_N = 100001;

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

void eratos(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;
    }
  }
}

int main() {
  eratos(MAX_N);
  double m, a, b;
  while (cin >> m >> a >> b and (m or a or b)) {
    double best = 0, P = 0, Q = 0;
    for (double p = 2; p <= m; ++p) {
      if (!is_prime[(int)p])
        continue;
      for (double q = 2; q <= m; ++q) {
        if (!is_prime[(int)q])
          continue;
        if (a / b > p / q or p / q > 1.0)
          continue;
        if (p * q > m)
          continue;
        if (best < p * q) {
          best = p * q;
          P = p;
          Q = q;
        }
      }
    }
    cout << P << ' ' << Q << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define PMAX 100000
bool prime[PMAX];
void primefy() {
  for (int i = 0; i < PMAX; i++) {
    prime[i] = true;
  }
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < sqrt(PMAX); i++) {
    if (prime[i]) {
      for (int j = i + i; j < PMAX; j += i) {
        prime[j] = false;
      }
    }
  }
}

int main(void) {
  primefy();
  vector<int> prime_list;
  int cnt = 0;
  for (int i = 0; i < PMAX; i++) {
    if (prime[i]) {
      prime_list.push_back(i);
      cnt++;
    }
  }

  int m, a, b;
  while (cin >> m >> a >> b, m | a | b) {
    int p_max, q_max;
    p_max = q_max = 0;
    for (int i = 0; i < cnt; i++) {
      if (prime_list[i] * 2 > m)
        break;
      for (int j = i; j < cnt; j++) {
        if (prime_list[j] * 2 > m)
          break;
        if (prime_list[i] * prime_list[j] <= m &&
            a / (double)b <= prime_list[i] / (double)prime_list[j] &&
            prime_list[i] / (double)prime_list[j] <= 1.0 &&
            prime_list[i] * prime_list[j] > p_max * q_max) {
          p_max = prime_list[i];
          q_max = prime_list[j];
        }
      }
    }
    cout << p_max << " " << q_max << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define PMAX 100000
bool prime[PMAX];
void primefy() {
  for (int i = 0; i < PMAX; i++) {
    prime[i] = true;
  }
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < sqrt(PMAX); i++) {
    if (prime[i]) {
      for (int j = i + i; j < PMAX; j += i) {
        prime[j] = false;
      }
    }
  }
}

void solve(int a, int b, int m, int p, int q, int &pq_max, int &p_max,
           int &q_max) {
  if (p * q <= m && a / (double)b <= p / (double)q && p / (double)q <= 1.0) {
    if (pq_max < p * q) {
      pq_max = p * q;
      p_max = p;
      q_max = q;
    }
  }
}

int main(void) {
  primefy();
  vector<int> prime_list;
  int cnt = 0;
  for (int i = 0; i < PMAX; i++) {
    if (prime[i]) {
      prime_list.push_back(i);
      cnt++;
    }
  }

  int m, a, b;
  while (cin >> m >> a >> b, m | a | b) {
    int p_max, q_max, pq_max;
    p_max = q_max = pq_max = 0;
    for (int i = 0; i < cnt; i++) {
      for (int j = i; j < cnt; j++) {
        int p = prime_list[i];
        int q = prime_list[j];
        solve(a, b, m, p, q, pq_max, p_max, q_max);
      }
    }
    cout << p_max << " " << q_max << endl;
  }

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

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

vector<int> make_prime(int N) {
  bool p[N + 1];
  memset(p, true, sizeof(p));
  p[0] = p[1] = false;
  for (int i = 0; i * i < N; i++) {
    if (p[i]) {
      for (int j = 2 * i; j < N; j += i) {
        p[j] = false;
      }
    }
  }
  vector<int> ret;
  for (int i = 0; i <= N; i++) {
    if (p[i])
      ret.push_back(i);
  }
  return ret;
}

int main() {
  vector<int> prime = make_prime(50000);
  int m, a, b;
  while (cin >> m >> a >> b, m | a | b) {
    double a_b = (double)a / (double)b;
    int max_p = 0;
    int ans1, ans2;
    for (int i = 0; i < prime.size(); i++) {
      if (prime[i] * prime[i] > m)
        break;
      for (int j = i; j < prime.size(); j++) {
        int M = prime[i] * prime[j];
        if (M > m)
          break;
        if ((M <= m) && (a_b <= (double)prime[i] / (double)prime[j])) {
          if (max_p <= M) {
            max_p = M;
            ans1 = prime[i], ans2 = prime[j];
          }
        }
      }
    }
    cout << ans1 << ' ' << ans2 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

vector<int> make_prime(int N) {
  bool p[N + 1];
  memset(p, true, sizeof(p));
  p[0] = p[1] = false;
  for (int i = 0; i * i < N; i++) {
    if (p[i]) {
      for (int j = 2 * i; j < N; j += i) {
        p[j] = false;
      }
    }
  }
  vector<int> ret;
  for (int i = 0; i <= N; i++) {
    if (p[i])
      ret.push_back(i);
  }
  return ret;
}

int main() {
  vector<int> prime = make_prime(100010);
  cout << prime.size() << endl;
  int m, a, b;
  while (cin >> m >> a >> b, m | a | b) {
    double a_b = (double)a / (double)b;
    int max_p = 0;
    int ans1, ans2;
    for (int i = 0; i < prime.size(); i++) {
      for (int j = i; j < prime.size(); j++) {
        int M = prime[i] * prime[j];
        if ((M <= m) && (a_b <= (double)prime[i] / (double)prime[j])) {
          if (max_p <= M) {
            max_p = M;
            ans1 = prime[i], ans2 = prime[j];
          }
        }
      }
    }
    cout << ans1 << ' ' << ans2 << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

#define for_(i, a, b) for (int i = a; i < b; i++)

int m, a, b;
int MAX_I = 50001;

vector<int> prime;
void make_prime() {
  vector<bool> isprime(MAX_I, true);
  for_(i, 2, MAX_I) {
    if (isprime[i]) {
      prime.push_back(i);
      for (int j = 2 * i; j < MAX_I; j += i)
        isprime[j] = false;
    }
  }
}

void solve() {
  double rate = (double)a / (double)b;

  int maxS = 0;
  int ansp = -1, ansq = -1;

  int psize = (int)prime.size();

  for_(i, 0, psize) {
    int p = prime[i];
    int t = min(m / p, p * b / a);

    for_(j, 0, psize) {
      int q = prime[j];
      if (q > t)
        break;
      double fruc = (double)p / (double)q;

      if (rate <= fruc && fruc <= 1.0) {
        int S = p * q;
        if (S <= m && maxS < S) {
          maxS = S;
          ansp = p;
          ansq = q;
        }
      }
    }
  }

  cout << ansp << " " << ansq << endl;
}

int main() {
  make_prime();

  while (cin >> m >> a >> b, m) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define for_(i, a, b) for (int i = a; i < b; i++)

int m, a, b;
int MAX_I = 50001;

vector<int> prime;
void make_prime() {
  vector<bool> isprime(MAX_I, true);
  for_(i, 2, MAX_I) {
    if (isprime[i]) {
      prime.push_back(i);
      for (int j = 2 * i; j < MAX_I; j += i)
        isprime[j] = false;
    }
  }
}

void solve() {
  double rate = (double)a / (double)b;

  int maxS = 0;
  int ansp = -1, ansq = -1;

  int psize = (int)prime.size();

  for_(i, 0, psize) {
    int p = prime[i];

    for_(j, 0, psize) {
      int q = prime[j];
      double fruc = (double)p / (double)q;

      if (rate <= fruc && fruc <= 1.0) {
        int S = p * q;
        if (S <= m && maxS < S) {
          maxS = S;
          ansp = p;
          ansq = q;
        }
      }
    }
  }

  cout << ansp << " " << ansq << endl;
}

int main() {
  make_prime();

  while (cin >> m >> a >> b, m) {
    solve();
  }

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

#include <iostream>
using namespace std;
int isPrime(int n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return 0;
  return 1;
}
int main() {
  int m, a, b;
  int i, j, k;
  int memo[200001] = {};
  for (i = 2; i < 200001; i++)
    memo[i] = isPrime(i);
  cin >> m >> a >> b;
  while ((m + a + b) != 0) {
    int p, q, o = 0;
    for (i = 1; i * i <= m; i++) {

      for (j = i; j <= b * i / a; j++) {
        if (j < 100001) {
          if (memo[i] * memo[j] == 1) {
            if (o < i * j && i * j <= m) {
              o = i * j;
              p = i;
              q = j;
            }
          }
        }
      }
    }
    // cout << o << endl;
    cout << p << " " << q << endl;
    cin >> m >> a >> b;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int isPrime(int n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return 0;
  return 1;
}
int main() {
  int m, a, b;
  int i, j, k;
  int memo[200001] = {};
  for (i = 2; i < 200001; i++)
    memo[i] = isPrime(i);
  cin >> m >> a >> b;
  while ((m + a + b) != 0) {
    int p, q, o = 0;
    for (i = 1; i * i <= m; i++) {

      for (j = i; j <= b * i / a; j++) {
        if (memo[i] * memo[j] == 1) {
          if (o < i * j && i * j <= m) {
            o = i * j;
            p = i;
            q = j;
          }
        }
      }
    }
    // cout << o << endl;
    cout << p << " " << q << endl;
    cin >> m >> a >> b;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define pb push_back
typedef long long ll;
typedef complex<int> P;

const int NMAX = 100000;
vector<int> pnum_;

void ini() {
  bool prime[NMAX];
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < NMAX; i++) {
    for (int j = 2 * i; j < NMAX; j += i) {
      prime[j] = false;
    }
  }
  for (int i = 0; i < NMAX; i++) {
    if (prime[i])
      pnum_.pb(i);
  }
}

bool solve() {
  int m, a, b;
  cin >> m >> a >> b;
  if (m == 0 && a == 0 && b == 0)
    return false;
  double c = (double)a / b;

  vector<int> pnum;
  for (int i = 0; i < pnum_.size() && pnum_[i] < m; i++) {
    pnum.pb(pnum_[i]);
  }

  int p = 0, q = 0;
  for (int i = 0; i < pnum.size() && pnum[i] * pnum[i] < m; i++) {
    for (int j = i; j < pnum.size(); j++) {
      double p2 = pnum[i], q2 = pnum[j];
      if (p2 * q2 > m || c > p2 / q2)
        break;
      if (p2 * q2 <= m && c <= p2 / q2) {
        if (p2 * q2 >= p * q) {
          p = p2;
          q = q2;
        }
      }
    }
  }

  cout << p << " " << q << endl;
  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);

  ini();
  while (solve())
    ;

  return 0;
}


Error: TLE

Fixed submission:


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define pb push_back
typedef long long ll;
typedef complex<int> P;

const int NMAX = 100000;
vector<int> pnum_;

void ini() {
  bool prime[NMAX];
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < NMAX; i++) {
    for (int j = 2 * i; j < NMAX; j += i) {
      prime[j] = false;
    }
  }
  for (int i = 0; i < NMAX; i++) {
    if (prime[i])
      pnum_.pb(i);
  }
}

bool solve() {
  int m, a, b;
  cin >> m >> a >> b;
  if (m == 0 && a == 0 && b == 0)
    return false;
  double c = (double)a / b;

  vector<int> pnum;
  for (int i = 0; i < pnum_.size() && pnum_[i] < m; i++) {
    pnum.pb(pnum_[i]);
  }
  reverse(pnum.begin(), pnum.end());

  int p = 0, q = 0;
  int i2 = pnum.size();
  for (int i = 0; i < i2; i++) {
    for (int j = i; j < pnum.size(); j++) {
      int p2 = pnum[j], q2 = pnum[i];
      if ((double)p2 / q2 < c)
        break;
      if (p2 * q2 <= m) {
        if (p2 * q2 >= p * q) {
          p = p2;
          q = q2;
          i2 = j;
        }
        break;
      }
    }
  }

  cout << p << " " << q << endl;
  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);

  ini();
  while (solve())
    ;

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

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

const static int M_MAX = 999999;

int main() {
  int era[M_MAX + 1] = {0};

  vector<int> primes;
  era[0] = era[1] = 1;
  for (int i = 2; i <= M_MAX; i++) {
    if (era[i]) {
      continue;
    }
    primes.push_back(i);
    for (int j = i + i; j <= M_MAX; j += i) {
      era[j] = 1;
    }
  }
  int pLen = primes.size();

  while (1) {
    int m, a, b;
    cin >> m >> a >> b;
    if (!m && !a && !b) {
      return EXIT_SUCCESS;
    }

    int ansP = -1, ansQ = -1;
    for (int i = 0; i < pLen; i++) {
      for (int j = 0; j < i + 1; j++) {
        int p = primes[j];
        int q = primes[i];
        if (p * q > m) {
          break;
        }
        if (a * q <= b * p) {
          if (ansP == -1 || p * q > ansP * ansQ) {
            ansP = p;
            ansQ = q;
          }
        }
      }
    }
    cout << ansP << " " << ansQ << endl;
  }
}

Error: TLE

Fixed submission:

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

const static int M_MAX = 999999;

int main() {
  int era[M_MAX + 1] = {0};

  vector<int> primes;
  era[0] = era[1] = 1;
  for (int i = 2; i <= M_MAX; i++) {
    if (era[i]) {
      continue;
    }
    primes.push_back(i);
    for (int j = i + i; j <= M_MAX; j += i) {
      era[j] = 1;
    }
  }
  int pLen = primes.size();

  while (1) {
    int m, a, b;
    cin >> m >> a >> b;
    if (!m && !a && !b) {
      return EXIT_SUCCESS;
    }

    int ansP = -1, ansQ = -1;
    for (int i = 0; primes[i] <= m; i++) {
      for (int j = i; primes[j] <= m; j++) {
        int p = primes[i];
        int q = primes[j];
        if (p * q <= m && a * q <= b * p) {
          if (ansP == -1 || p * q > ansP * ansQ) {
            ansP = p;
            ansQ = q;
          }
        }
      }
    }
    cout << ansP << " " << ansQ << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

#define INF 999999999
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int pr[100001];

void erato() {
  pr[0] = 0;
  pr[1] = 0;
  pr[2] = 1;
  for (int i = 3; i <= 100000; i++) {
    pr[i] = 1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        pr[i] = 0;
        break;
      }
    }
  }
}

int main() {
  long long int m, a, b, p, q;
  erato();
  while (1) {
    cin >> m >> a >> b;
    if (!m)
      break;
    p = 1;
    q = 1;
    for (long long int i = 2; i <= m; i++) {
      for (long long int j = i; j * i <= m; j++) {
        if (!pr[i] || !pr[j])
          continue;
        if (i * j <= m && a * j <= i * b && i * j > p * q) {
          p = i;
          q = j;
        }
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

using namespace std;

#define INF 999999999
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int pr[100001];

void erato() {
  pr[0] = 0;
  pr[1] = 0;
  pr[2] = 1;
  for (int i = 3; i <= 100000; i++) {
    pr[i] = 1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        pr[i] = 0;
        break;
      }
    }
  }
}

int main() {
  int m, a, b, p, q;
  erato();
  while (1) {
    cin >> m >> a >> b;
    if (!m)
      break;
    p = 1;
    q = 1;
    for (int i = 2; i <= m; i++) {
      for (int j = i; j * i <= m; j++) {
        if (!pr[i] || !pr[j])
          continue;
        if (i * j <= m && a * j <= i * b && i * j > p * q) {
          p = i;
          q = j;
        }
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {

  vector<long long> prime;
  prime.push_back(2);
  prime.push_back(3);
  prime.push_back(5);

  for (int i = 7; prime.back() < 100000 / 2; i += 2) {
    bool ok = true;
    for (int j = 0; prime[j] * prime[j] <= i && ok; j++) {
      if (i % prime[j] == 0)
        ok = false;
    }
    if (ok)
      prime.push_back(i);
  }

  long long m, a, b;
  while (cin >> m >> a >> b, m | a | b) {
    long p = 0, q = 0;
    for (long i = 0; i < prime.size(); i++) {
      for (long j = i; j < prime.size() && prime[i] * prime[j] <= m; j++) {
        if (a * prime[j] <= b * prime[i] && p * q < prime[i] * prime[j]) {
          p = prime[i];
          q = prime[j];
        }
      }
    }
    cout << p << " " << q << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {

  vector<long long> prime;
  prime.push_back(2);
  prime.push_back(3);
  prime.push_back(5);

  for (int i = 7; prime.back() < 100000; i += 2) {
    bool ok = true;
    for (int j = 0; prime[j] * prime[j] <= i && ok; j++) {
      if (i % prime[j] == 0)
        ok = false;
    }
    if (ok)
      prime.push_back(i);
  }

  long long m, a, b;
  while (cin >> m >> a >> b, m | a | b) {
    long p = 0, q = 0;
    for (long i = 0; i < prime.size(); i++) {
      for (long j = i; j < prime.size(); j++) {
        if (prime[i] * prime[j] <= m && a * prime[j] <= b * prime[i] &&
            p * q < prime[i] * prime[j]) {
          p = prime[i];
          q = prime[j];
        }
      }
    }
    cout << p << " " << q << endl;
  }

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

// 31
#include <iostream>
#include <vector>

using namespace std;

int main() {
  bool cmp[100000] = {};
  vector<int> prm;
  for (int i = 2; i < 100000; i++) {
    if (!cmp[i]) {
      prm.push_back(i);
      for (int j = 2; j * i < 100000; j++) {
        cmp[i * j] = true;
      }
    }
  }
  for (int m, a, b; cin >> m >> a >> b, m | a | b;) {
    int ca = 0, cb = 0;
    for (int i = 0; i < prm.size(); i++) {
      for (int j = i; j < prm.size(); j++) {
        long long ar = (long long)prm[i] * prm[j];
        if (ar > m)
          break;
        if (ca * cb <= ar && prm[j] * a <= prm[i] * b) {
          ca = prm[i];
          cb = prm[j];
        }
      }
    }
    cout << ca << ' ' << cb << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

// 31
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  bool cmp[100000] = {};
  vector<int> prm;
  for (int i = 2; i < 100000; i++) {
    if (!cmp[i]) {
      prm.push_back(i);
      for (int j = 2; j * i < 100000; j++) {
        cmp[i * j] = true;
      }
    }
  }
  for (int m, a, b; cin >> m >> a >> b, m | a | b;) {
    int ca = 0, cb = 0;
    for (int i = 0; i < prm.size(); i++) {
      for (int j = i; j < prm.size(); j++) {
        int ar = prm[i] * prm[j];
        if (ca * cb <= ar && ar <= m && prm[j] * a <= prm[i] * b) {
          ca = prm[i];
          cb = prm[j];
        }
      }
    }
    cout << ca << ' ' << cb << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

bool is_prime[100001];
void prime(int n) {
  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] == true) {
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

int main() {
  int m, a, b;
  prime(100000);
  while (cin >> m >> a >> b, m) {
    int p = 0, q = 0;
    for (int i = 1; i * i <= m; i++) {
      if (!is_prime[i])
        continue;
      for (int j = i; j <= m / i + 1; j++) {
        if (!is_prime[j])
          continue;
        if (q * p < i * j && i * j <= m && a * j <= i * b && i * b <= b * j) {
          p = j;
          q = i;
        }
      }
    }
    cout << q << " " << p << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool is_prime[100001];
void prime(int n) {
  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] == true) {
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

int main() {
  int m, a, b;
  prime(100000);
  while (cin >> m >> a >> b, m) {
    int p = 0, q = 0;
    for (int i = 1; i * i <= m; i++) {
      if (!is_prime[i])
        continue;
      for (int j = i; j <= m; j++) {
        if (!is_prime[j])
          continue;
        if (q * p < i * j && i * j <= m && a * j <= i * b && i * b <= b * j) {
          p = j;
          q = i;
        }
      }
    }
    cout << q << " " << p << endl;
  }
  return 0;
}