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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int stoi(string x) {
  stringstream ss;
  ss << x;
  int tmp;
  ss >> tmp;
  return tmp;
}
string itos(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
vector<int> ta;
bool is(int n) {
  if (n == 2)
    return true;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
void init() {
  int i = 2;
  while (ta.size() <= 100000) {
    if (is(i))
      ta.push_back(i);
    i++;
  }
}
int m, a, b, a1 = 0, a2 = 0;
int main() {
  init();
  // for(int i=0;i<10;i++)cout<<ta[i]<<" ";cout<<endl;
  while (true) {
    cin >> m >> a >> b;
    if (m + a + b == 0)
      break;
    a1 = 0, a2 = 0;
    for (int i = 0; ta[i] <= m; i++) {
      for (int j = 0; ta[j] <= m; j++) {
        // if(i>j)continue;
        int p = ta[j], q = ta[i];
        double a_b = (double)a / (double)b, p_q = (double)p / (double)q;
        if (p * q <= m && a_b <= p_q && p_q <= 1.0 && a1 * a2 < p * q) {
          a1 = min(q, p), a2 = max(p, q);
        }
        if (p * q > m)
          break;
      }
    }
    cout << a1 << " " << a2 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int stoi(string x) {
  stringstream ss;
  ss << x;
  int tmp;
  ss >> tmp;
  return tmp;
}
string itos(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
vector<int> ta;
bool is(int n) {
  if (n == 2)
    return true;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
void init() {
  int i = 2;
  while (ta.size() <= 100000) {
    if (is(i))
      ta.push_back(i);
    i++;
  }
}
int m, a, b, a1 = 0, a2 = 0;
int main() {
  init();
  // for(int i=0;i<10;i++)cout<<ta[i]<<" ";cout<<endl;
  while (true) {
    cin >> m >> a >> b;
    if (m + a + b == 0)
      break;
    a1 = 0, a2 = 0;
    for (int i = 0; ta[i] <= m; i++) {
      for (int j = 0; ta[j] <= m; j++) {
        // if(i>j)continue;
        int p = ta[j], q = ta[i];
        double a_b = (double)a / (double)b, p_q = (double)p / (double)q;
        if (p * q <= m && a_b <= p_q && p_q <= 1.0 && a1 * a2 < p * q) {
          a1 = min(q, p), a2 = max(p, q);
        }
      }
    }
    cout << a1 << " " << a2 << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

bool p[100050];
vector<long long> prime;
void make_prime() {
  for (int i = 0; i < 100050; i++)
    p[i] = true;
  p[0] = p[1] = false;
  prime.push_back(2);
  for (int i = 4; i < 100050; i += 2)
    p[i] = false;
  for (int i = 3; i * i < 100050; i += 2) {
    if (p[i]) {
      // cout << i << endl;
      for (int j = i * i; j < 100050; j += i) {
        p[j] = false;
      }
    }
  }
  // cout << prime.size() << endl;
  for (int i = 0; i < 100050; i++) {
    if (p[i])
      prime.push_back((long long)i);
  }
  // cout << prime.size() << endl;
}
// pq &#8804; m and a/b &#8804; p/q &#8804; 1
// pq -> max
int main() {
  make_prime();
  long long m, a, b;
  while (cin >> m >> a >> b, m) {
    long long max = 0;
    long long p = -1, q = -1;
    for (int i = 0; i < prime.size(); i++) {
      for (int j = i; j < prime.size(); j++) {
        long long area = prime[i] * prime[j];
        if (m < area)
          break;
        if (max < area && area <= m && prime[j] * a <= prime[i] * b) {
          max = area;
          p = prime[i];
          q = prime[j];
        }
      }
    }
    if (p <= q)
      cout << p << " " << q << endl;
    else
      cout << q << " " << p << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

bool p[100050];
vector<int> prime;
void make_prime() {
  for (int i = 0; i < 100050; i++)
    p[i] = true;
  p[0] = p[1] = false;
  prime.push_back(2);
  for (int i = 4; i < 100050; i += 2)
    p[i] = false;
  for (int i = 3; i * i < 100050; i += 2) {
    if (p[i]) {
      // cout << i << endl;
      prime.push_back(i);
      for (int j = i + i; j < 100050; j += i) {
        p[j] = false;
      }
    }
  }
  // cout << prime.size() << endl;
  prime.clear();
  for (int i = 0; i < 100050; i++) {
    if (p[i])
      prime.push_back(i);
  }
  // cout << prime.size() << endl;
}
// pq &#8804; m and a/b &#8804; p/q &#8804; 1
// pq -> max
int main() {
  make_prime();
  long long m, a, b;
  while (cin >> m >> a >> b, m) {
    long long max = 0;
    long long p = -1, q = -1;
    for (int i = 0; i < prime.size(); i++) {
      for (int j = i; j < prime.size(); j++) {
        long long area = prime[i] * prime[j];
        if (max < area && area <= m && a * prime[j] <= b * prime[i]) {
          max = area;
          p = prime[i];
          q = prime[j];
        }
        if (m < area)
          break;
      }
    }
    if (p <= q)
      cout << p << " " << q << endl;
    else
      cout << q << " " << p << endl;
  }

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

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

int main() {

  // エラトステネスの篩
  vector<bool> prime(1000000, true); // 1000000までで、素数ならtrue
  prime[0] = prime[1] = false;
  for (int i = 2; i < 1000000; i++) {
    if (prime[i] == true) {
      for (int j = 2 * i; j < 1000000; j += i) {
        prime[j] = false;
      }
    }
  }

  vector<int> sosuu; // 素数の表
  for (int i = 0; i < 1000000; i++) {
    if (prime[i])
      sosuu.push_back(i);
  }

  while (1) {

    int m, a, b;
    cin >> m >> a >> b;
    if (!m)
      break;

    int max = 0;
    int p, q;
    int end = (int)(m / 2) + 3;
    for (int i = 0; sosuu[i] < end; i++) {
      for (int j = i; sosuu[j] < end; j++) {
        if (sosuu[i] * sosuu[j] <= m && sosuu[j] * a <= sosuu[i] * b) {
          if (max < sosuu[i] * sosuu[j]) {
            max = sosuu[i] * sosuu[j];
            p = sosuu[i];
            q = sosuu[j];
          }
        }

        if (sosuu[i] * sosuu[j] >= m)
          break;
      }
      if (sosuu[i] * sosuu[i] >= m)
        break;
    }

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

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {

  // エラトステネスの篩
  vector<bool> prime(1000000, true); // 1000000までで、素数ならtrue
  prime[0] = prime[1] = false;
  for (int i = 2; i < 1000000; i++) {
    if (prime[i] == true) {
      for (int j = 2 * i; j < 1000000; j += i) {
        prime[j] = false;
      }
    }
  }

  vector<int> sosuu; // 素数の表
  for (int i = 0; i < 1000000; i++) {
    if (prime[i])
      sosuu.push_back(i);
  }

  while (1) {

    int m, a, b;
    cin >> m >> a >> b;
    if (!m)
      break;

    int max = 0;
    int p, q;
    for (int i = 0; sosuu[i] < m; i++) {
      for (int j = i; sosuu[j] < m; j++) {
        if (sosuu[i] * sosuu[j] < m && sosuu[j] * a <= sosuu[i] * b) {
          if (max < sosuu[i] * sosuu[j]) {
            max = sosuu[i] * sosuu[j];
            p = sosuu[i];
            q = sosuu[j];
          }
        }

        // if(sosuu[i]*sosuu[j] >= m) break;
      }
      /// if(sosuu[i]*sosuu[i] >= m) break;
    }

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

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

#include <iostream>
#include <string>
#include <vector>

using namespace std;

const int MX = 100000;
bool isprime[MX];

vector<int> getPrimes() {
  vector<int> ret;
  fill_n(isprime, MX, true);
  isprime[0] = isprime[1] = false;
  for (int i = 2; i <= MX; ++i) {
    if (!isprime[i])
      continue;
    ret.push_back(i);
    for (int j = i * i; 0 < j && j <= MX; j += i) {
      isprime[j] = false;
    }
  }
  return ret;
}

int main() {
  vector<int> primes = getPrimes();
  long long m, a, b;
  while (1) {
    cin >> m >> a >> b;
    if (!m && !a && !b)
      break;
    long long pq = 0;
    pair<int, int> ans;
    for (int i = 0; i < (int)primes.size(); ++i) {
      long long p = primes[i];
      if (p * p > m)
        break;
      for (int j = i; j < (int)primes.size(); ++j) {
        long long q = primes[j];
        if (p * q > m || a * q > b * p)
          break;
        if (pq < p * q) {
          pq = p * q;
          ans.first = p;
          ans.second = q;
        }
      }
    }
    cout << ans.first << " " << ans.second << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

const int MX = 100000;
bool isprime[MX];

vector<int> getPrimes() {
  vector<int> ret;
  fill_n(isprime, MX, true);
  isprime[0] = isprime[1] = false;
  for (int i = 2; i <= MX; ++i) {
    if (!isprime[i])
      continue;
    ret.push_back(i);
    for (int j = i * i; 0 < j && j <= MX; j += i) {
      isprime[j] = false;
    }
  }
  return ret;
}

int main() {
  vector<int> primes = getPrimes();
  long long m, a, b;
  while (1) {
    cin >> m >> a >> b;
    if (!m && !a && !b)
      break;
    long long pq = 0;
    pair<int, int> ans;
    for (int i = 0; i < (int)primes.size(); ++i) {
      for (int j = i; j < (int)primes.size(); ++j) {
        long long p = primes[i];
        long long q = primes[j];
        if (p * q <= m && a * q <= b * p) {
          if (pq < p * q) {
            pq = p * q;
            ans.first = p;
            ans.second = q;
          }
        }
      }
    }
    cout << ans.first << " " << ans.second << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int SIZ = 100000;

vector<int> getPrimes() {
  vector<int> primes;
  int sieve[SIZ];
  fill_n(sieve, SIZ, true);
  sieve[0] = sieve[1] = false;
  primes.push_back(2);
  for (int i = 4; i < SIZ; i += 2) {
    sieve[i] = false;
  }
  for (int i = 3; i * i < SIZ; i += 2) {
    if (!sieve[i])
      continue;
    for (int j = i * 2; j < SIZ; j += i) {
      sieve[j] = false;
    }
  }
  for (int i = 3; i < SIZ; i += 2) {
    if (sieve[i])
      primes.push_back(i);
  }
  return primes;
}

int main() {
  ios::sync_with_stdio(false);
  vector<int> primes = getPrimes();
  int m, a, b;
  while (1) {
    cin >> m >> a >> b;
    if (!m && !a && !b)
      break;
    int tp, tq, p = 0, q = 0, max_m = 0;
    for (int i = 0; i < (int)primes.size(); ++i) {
      for (int j = i; j < (int)primes.size(); ++j) {
        tp = primes[i];
        tq = primes[j];
        if (tp * tq < 0)
          break;
        if (m < tp * tq || b * tp < a * tq) {
          break;
        }
        if (max_m < tp * tq) {
          p = tp;
          q = tq;
          max_m = tp * tq;
        }
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int SIZ = 100000;

vector<int> getPrimes() {
  vector<int> primes;
  int sieve[SIZ];
  fill_n(sieve, SIZ, true);
  sieve[0] = sieve[1] = false;
  primes.push_back(2);
  for (int i = 4; i < SIZ; i += 2) {
    sieve[i] = false;
  }
  for (int i = 3; i * i < SIZ; i += 2) {
    if (!sieve[i])
      continue;
    for (int j = i * 2; j < SIZ; j += i) {
      sieve[j] = false;
    }
  }
  for (int i = 3; i < SIZ; i += 2) {
    if (sieve[i])
      primes.push_back(i);
  }
  return primes;
}

int main() {
  vector<int> primes = getPrimes();
  int m, a, b;
  while (1) {
    cin >> m >> a >> b;
    if (!m && !a && !b)
      break;
    int tp, tq, p = 0, q = 0, max_m = 0;
    for (int i = 0; i < (int)primes.size(); ++i) {
      for (int j = i; j < (int)primes.size(); ++j) {
        tp = primes[i];
        tq = primes[j];
        if (m < tp * tq || b * tp < a * tq) {
          break;
        }
        if (max_m < tp * tq) {
          p = tp;
          q = tq;
          max_m = tp * tq;
        }
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int m, a, b;
  bool pp[100001];
  vector<int> prime;
  {
    memset(pp, true, sizeof(pp));
    pp[0] = pp[1] = false;
    for (int i = 2; i < 100001; i++) {
      if (pp[i]) {
        prime.push_back(i);
        for (int j = i + i; j < 100001; j += i)
          pp[j] = false;
      }
    }
  }

  for (; cin >> m >> a >> b, m;) {
    for (; m > 0;) {
      for (int i = 0; i < prime.size(); i++) {
        if (prime[i] > m / 2)
          break;
        if (m % prime[i] == 0 && pp[m / prime[i]] &&
            ((double)a / b) <= ((double)(m / prime[i]) / prime[i]) &&
            ((double)(m / prime[i]) / prime[i]) <= 1) {
          cout << m / prime[i] << " " << prime[i] << endl;
          m = -1;
          i = -1;
        }
      }
      m--;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int m, a, b;
  bool pp[100001];
  vector<int> prime;
  {
    memset(pp, true, sizeof(pp));
    pp[0] = pp[1] = false;
    for (int i = 2; i < 100001; i++) {
      if (pp[i]) {
        prime.push_back(i);
        for (int j = i + i; j < 100001; j += i)
          pp[j] = false;
      }
    }
  }

  for (; cin >> m >> a >> b, m;) {
    for (; m > 0;) {
      for (int i = 0; i < prime.size(); i++) {
        if (prime[i] > m)
          continue;
        if (m % prime[i] == 0 && pp[m / prime[i]] &&
            ((double)a / b) <= ((double)(m / prime[i]) / prime[i]) &&
            ((double)(m / prime[i]) / prime[i]) <= 1) {
          cout << m / prime[i] << " " << prime[i] << endl;
          m = -1;
          i = -1;
        }
      }
      m--;
    }
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MAX = 50000;

vector<int> prime;

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

signed main() {
  for (int i = 2; i < MAX; i++) {
    if (is_prime(i))
      prime.push_back(i);
  }
  while (true) {
    int m, a, b;
    cin >> m >> a >> b;
    if (!m && !a && !b)
      return 0;
    int p, q;
    p = q = 1;
    for (int i = 0; i < prime.size(); i++) {
      int ptmp = prime[i];
      for (int j = i; j < prime.size(); j++) {
        int qtmp = prime[j];
        if (ptmp * qtmp > m)
          break;
        double res = (double)ptmp / qtmp;
        if (res < (double)a / b)
          break;
        if (ptmp * qtmp > p * q) {
          p = ptmp;
          q = qtmp;
        }
      }
    }
    cout << p << " " << q << endl;
  }
}


Error: TLE

Fixed submission:

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

const int MAX = 100001;

vector<int> prime;

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

signed main() {
  for (int i = 2; i < MAX; i++) {
    if (is_prime(i))
      prime.push_back(i);
  }
  while (true) {
    int m, a, b;
    cin >> m >> a >> b;
    if (!m && !a && !b)
      return 0;
    int p, q;
    p = q = 1;
    for (int i = 0; i < prime.size(); i++) {
      int ptmp = prime[i];
      for (int j = i; j < prime.size(); j++) {
        int qtmp = prime[j];
        if (ptmp * qtmp > m)
          break;
        double res = (double)ptmp / qtmp;
        if (res < (double)a / b)
          break;
        if (ptmp * qtmp > p * q) {
          p = ptmp;
          q = qtmp;
        }
      }
    }
    cout << p << " " << q << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, b) for (int i = 0; i < b; i++)
#define repi(i, a, b) for (int i = a; i < b; i++)
#define MAX 100000
typedef vector<int> vec;

bool prime[MAX];
vec v;

void pcalc() {
  rep(i, MAX) { prime[i] = true; }
  prime[0] = false;
  prime[1] = false;
  repi(i, 2, MAX / 2) {
    if (prime[i]) {
      v.push_back(i);
      for (int j = i * 2; j < MAX / 2; j += i) {
        prime[j] = false;
      }
    }
  }
}

int main() {
  pcalc();
  int m, a, b;
  while (cin >> m >> a >> b, m) {
    int w, h, max = 0;
    for (int i = 0; v.size() && v[i] * v[i] <= m; i++) {
      for (int j = i; v.size() && v[i] * v[j] <= m; j++) {
        int p = v[i], q = v[j];
        if (p * b >= a * q && p * q > max) {
          max = p * q;
          w = p;
          h = q;
        }
      }
    }
    /*
    rep(i, v.size()){
        if( v[i].first * v[i].second > ans.first * ans.second ){
            ans = make_pair(v[i].first, v[i].second);
        }
    }
    */
    cout << w << ' ' << h << endl;
  }
}

Error: TLE

Fixed submission:

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

#define rep(i, b) for (int i = 0; i < b; i++)
#define repi(i, a, b) for (int i = a; i < b; i++)
#define max 100000
typedef vector<int> vec;

bool prime[max];
vec v;

void pcalc() {
  rep(i, max) { prime[i] = true; }
  prime[0] = false;
  prime[1] = false;
  repi(i, 2, max / 2) {
    if (prime[i]) {
      v.push_back(i);
      for (int j = i * 2; j < max / 2; j += i) {
        prime[j] = false;
      }
    }
  }
}

int main() {
  pcalc();
  int m, a, b;
  while (cin >> m >> a >> b, m) {
    int w, h, Max = 0;
    rep(i, v.size()) {
      repi(j, i, v.size()) {
        int p = v[i], q = v[j];
        if (p * q <= m && p * b >= a * q && p * q > Max) {
          Max = p * q;
          w = p;
          h = q;
        }
      }
    }
    /*
    rep(i, v.size()){
        if( v[i].first * v[i].second > ans.first * ans.second ){
            ans = make_pair(v[i].first, v[i].second);
        }
    }
    */
    cout << w << ' ' << h << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int m, a, b;
bool prime[100001];
vector<int> pp;
int main(void) {
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i = 2; i <= 100000; i++) {
    if (prime[i]) {
      pp.push_back(i);
      for (int j = i * 2; j <= 100000; j += i) {
        prime[j] = false;
      }
    }
  }
  while (1) {
    scanf("%d %d %d", &m, &a, &b);
    if (m + a + b == 0)
      break;
    int rp = 0, rq = 0;
    for (int i = 0; i < pp.size(); i++) {
      if (pp[i] * pp[i] > m)
        break;
      for (int j = i; j < pp.size(); j++) {
        if (pp[i] * pp[j] > m)
          break;
        if (a * pp[j] > b * pp[i])
          continue;
        if (rp * rq < pp[i] * pp[j]) {
          rp = pp[i];
          rq = pp[j];
        }
      }
    }
    printf("%d %d\\n", rp, rq);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int m, a, b;
bool prime[100001];
vector<int> pp;
int main(void) {
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i = 2; i <= 100000; i++) {
    if (prime[i]) {
      pp.push_back(i);
      for (int j = i * 2; j <= 100000; j += i) {
        prime[j] = false;
      }
    }
  }
  while (1) {
    scanf("%d %d %d", &m, &a, &b);
    if (m + a + b == 0)
      break;
    int rp = 0, rq = 0;
    for (int i = 0; i < pp.size(); i++) {
      int k = lower_bound(pp.begin(), pp.end(), m / pp[i]) - pp.begin();
      for (int j = max(k - 2, i); j < pp.size(); j++) {
        if (pp[i] * pp[j] >= m)
          break;
        if (a * pp[j] > b * pp[i])
          continue;
        if (rp * rq < pp[i] * pp[j]) {
          rp = pp[i];
          rq = pp[j];
        }
      }
    }
    printf("%d %d\\n", rp, rq);
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int judge(int n) {
  if (n < 2)
    return 0;
  if (n == 2)
    return 1;
  if (n % 2 == 0)
    return 0;
  for (int i = 3; i <= n / i; i += 2) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int m, a, b, prime[10000], n = 0, p, q;
  double ab;
  for (int i = 0; i < 10000; i++) {
    if (judge(i))
      prime[n++] = i;
  }
  while (1) {
    cin >> m >> a >> b;
    if (m == 0 && a == 0 && b == 0)
      break;
    ab = (double)a / b;
    p = 1;
    q = 1;
    for (int i = 0; i < n; i++) {
      for (int j = i; prime[i] * prime[j] <= m; j++) {
        if (prime[i] * prime[j] > p * q && ab <= (double)prime[i] / prime[j]) {
          p = prime[i];
          q = prime[j];
        }
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int judge(int n) {
  if (n < 2)
    return 0;
  if (n == 2)
    return 1;
  if (n % 2 == 0)
    return 0;
  for (int i = 3; i < n / i; i += 3) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int m, a, b, prime[100000], n = 0, p, q;
  double ab;
  for (int i = 0; i < 100000; i++) {
    if (judge(i))
      prime[n++] = i;
  }
  while (1) {
    cin >> m >> a >> b;
    if (m == 0 && a == 0 && b == 0)
      break;
    ab = (double)a / b;
    p = 1;
    q = 1;
    for (int i = 0; i < n; i++) {
      for (int j = i; prime[i] * prime[j] <= m; j++) {
        if (prime[i] * prime[j] > p * q && ab <= (double)prime[i] / prime[j]) {
          p = prime[i];
          q = prime[j];
        }
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}