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


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> i_i;

vector<ll> p(100000);

void era() {
  for (int i = 2; i < 100000; i++) {
    if (p[i] == 0)
      continue;
    int j = i;
    while (j < 100000) {
      j += i;
      if (j >= 100000)
        break;
      p[j] = 0;
    }
  }
}

int main() {
  rep(i, 100000) p[i] = i;
  era();
  for (;;) {
    int m, a, b;
    cin >> m >> a >> b;
    if (!m)
      break;
    int ans = 0, pp = 0, qq = 0;
    for (int i = m; i > 1; i--) {
      if (p[i] == 0 or i == 1)
        continue;
      for (int j = min(m / i, i); j >= i * a / b; j--) {
        if (i * j < ans)
          break;
        if (p[j] != 0 and i != 1 and i * j <= m and i * a <= j * b) {
          if (ans < i * j) {
            ans = i * j;
            pp = j;
            qq = i;
          }
        }
      }
    }
    cout << pp << " " << qq << endl;
  }
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> i_i;

vector<ll> p(100000);

void era() {
  for (int i = 2; i < 100000; i++) {
    if (p[i] == 0)
      continue;
    int j = i;
    while (j < 100000) {
      j += i;
      if (j >= 100000)
        break;
      p[j] = 0;
    }
  }
}

int main() {
  rep(i, 100000) p[i] = i;
  era();
  for (;;) {
    int m, a, b;
    cin >> m >> a >> b;
    if (!m)
      break;
    int ans = 0, pp = 0, qq = 0;
    for (int i = m / 2; i > 1; i--) {
      if (p[i] == 0)
        continue;
      for (int j = i; j >= i * a / b; j--) {
        if (i * j < ans)
          break;
        if (p[j] != 0 and i * j <= m) {
          if (ans < i * j) {
            ans = i * j;
            pp = j;
            qq = i;
          }
          break;
        }
      }
    }
    cout << pp << " " << qq << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

using namespace std;

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

  // sieve of eratosthenes
  vector<int> pnums(1000000, 0);
  for (int i = 2; i < 1000000; i++)
    pnums[i] = 1;
  for (int i = 2; i * i < 1000000; i++) {
    if (pnums[i]) {
      for (int j = i * i; j < 1000000; j += i) {
        pnums[j] = 0;
      }
    }
  }
  vector<int> primes;
  for (int i = 2; i < 10000; i++)
    if (pnums[i])
      primes.push_back(i);
  int m, a, b;
  while (cin >> m >> a >> b, m || a || b) {
    int p = 0, q = 0, ma = p * q;
    for (int i = 0; i < (int)primes.size(); i++) {
      for (int j = i; j < (int)primes.size(); j++) {
        if (primes[i] * primes[j] > m || a * primes[j] > b * primes[i])
          continue;
        if (ma < primes[i] * primes[j]) {
          p = primes[i];
          q = primes[j];
          ma = primes[i] * primes[j];
        }
      }
    }
    cout << p << " " << q << endl;
  }
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

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

  // sieve of eratosthenes
  vector<int> pnums(1000000, 0);
  for (int i = 2; i < 1000000; i++)
    pnums[i] = 1;
  for (int i = 2; i * i < 1000000; i++) {
    if (pnums[i]) {
      for (int j = i * i; j < 1000000; j += i) {
        pnums[j] = 0;
      }
    }
  }
  vector<int> primes;
  for (int i = 2; i < 100000; i++)
    if (pnums[i])
      primes.push_back(i);
  int m, a, b;
  while (cin >> m >> a >> b, m || a || b) {
    int p = 0, q = 0, ma = p * q;
    for (int i = 0; i < (int)primes.size(); i++) {
      for (int j = i; j < (int)primes.size(); j++) {
        if (primes[i] * primes[j] > m || a * primes[j] > b * primes[i])
          continue;
        if (ma < primes[i] * primes[j]) {
          p = primes[i];
          q = primes[j];
          ma = primes[i] * primes[j];
        }
      }
    }
    cout << p << " " << q << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// ??¨????????????????????????O(NloglogN?)
const ll MAX = 10004;
bool isPrime[MAX];
vector<int> prime;
void makePrime() {
  for (ll i = 0; i < MAX; i++)
    isPrime[i] = true;
  for (ll i = 2; i * i < MAX + 1; i++) {
    if (isPrime[i]) {
      for (ll j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  for (int i = 0; i < MAX; i++)
    if (isPrime[i])
      prime.push_back(i);
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  makePrime();
  int a, b, m;
  int n = prime.size();
  sort(prime.begin(), prime.end());
  while (cin >> m >> a >> b, m || a || b) {
    int p = 0, q = 0, mx = p * q;
    FOR(i, 0, n) {
      FOR(j, i, n) {
        if (prime[i] * prime[j] > m)
          break;
        if (a * prime[j] <= prime[i] * b && prime[i] * prime[j] <= m) {
          if (mx < prime[i] * prime[j]) {
            p = prime[i];
            q = prime[j];
            mx = prime[i] * prime[j];
          }
        }
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// ??¨????????????????????????O(NloglogN?)
const ll MAX = 100005;
bool isPrime[MAX];
vector<int> prime;
void makePrime() {
  for (ll i = 0; i < MAX; i++)
    isPrime[i] = true;
  for (ll i = 2; i * i < MAX + 1; i++) {
    if (isPrime[i]) {
      for (ll j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  for (int i = 0; i < MAX; i++)
    if (isPrime[i])
      prime.push_back(i);
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  makePrime();
  int a, b, m;
  int n = prime.size();
  sort(prime.begin(), prime.end());
  while (cin >> m >> a >> b, m || a || b) {
    int p = 0, q = 0, mx = p * q;
    FOR(i, 0, n) {
      FOR(j, i, n) {
        if (a * prime[j] <= prime[i] * b && prime[i] * prime[j] <= m) {
          if (mx < prime[i] * prime[j]) {
            p = prime[i];
            q = prime[j];
            mx = prime[i] * prime[j];
          }
        }
      }
    }
    cout << p << " " << q << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
const int N = 30000;
using namespace std;
bool a[N];
vector<int> prime;
void erast() {
  fill(a, a + N, true);
  a[0] = a[1] = false;
  for (int i = 2; i * i <= N; ++i) {
    if (a[i] == false)
      continue;
    for (int j = i * i; j <= N; j += i) {
      a[j] = false;
    }
  }
  REP(i, N) {
    if (a[i] == false)
      continue;
    prime.push_back(i);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  erast();
  int m, a, b;
  while (cin >> m >> a >> b, m) {
    int maxpq = 0, maxp = 0, maxq = 0;
    REP(i, prime.size()) {
      for (int j = i; j < prime.size(); j++) {
        int p = prime[i], q = prime[j];
        if (p <= q && p * q <= m && a * q <= b * p && maxpq <= p * q) {
          maxpq = p * q;
          maxp = p;
          maxq = q;
        }
      }
    }
    cout << maxp << ' ' << maxq << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
const int N = 50000;
using namespace std;
bool a[N];
vector<int> prime;
vector<pair<int, double>> primepair;
void erast() {
  fill(a, a + N, true);
  a[0] = a[1] = false;
  for (int i = 2; i * i <= N; ++i) {
    if (a[i] == false)
      continue;
    for (int j = i * i; j <= N; j += i) {
      a[j] = false;
    }
  }
  REP(i, N) {
    if (a[i] == false)
      continue;
    prime.push_back(i);
  }
  REP(i, prime.size()) {
    for (int j = i; j < prime.size(); j++) {
      primepair.push_back(
          make_pair(prime[i] * prime[j], (double)prime[i] / prime[j]));
    }
  }
  sort(primepair.begin(), primepair.end());
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  erast();
  int m, a, b;
  while (cin >> m >> a >> b, m) {
    double suitable_p = (double)a / b;
    for (auto itr =
             lower_bound(primepair.begin(), primepair.end(), make_pair(m, 5.0));
         ; itr--) {
      if (itr->first <= m && itr->second >= suitable_p) {
        cout << ceil(sqrt(itr->first * itr->second)) << ' '
             << ceil(sqrt(itr->first / itr->second)) << endl;
        break;
      }
      if (itr == primepair.begin())
        break;
    }
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bitset>
#include <stdio.h>
#include <vector>
#define N 50000
int main() {
  typedef long long L;
  std::bitset<N> x;
  std::vector<L> v;
  for (L i = 2; i < N; ++i)
    if (!x[i]) {
      v.push_back(i);
      for (L j = i * i; j < N; j += i)
        x[j] = 1;
    }
  int p, q, a, b, m;
  while (scanf("%d%d%d", &m, &a, &b), m) {
    p = q = 0;
    for (int i = 0; i < 5133; ++i)
      for (int j = i; j < 5133; ++j) {
        if (v[i] * v[j] > m)
          break;
        if (a * v[j] <= v[i] * b && v[i] * v[j] > L(p) * q)
          p = v[i], q = v[j];
      }
    printf("%d %d\\n", p, q);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bitset>
#include <stdio.h>
#include <vector>
#define N 50000
int main() {
  long long i, j, k, p, q, a, b, m;
  std::bitset<N> x;
  std::vector<int> v;
  for (i = 2; i < N; ++i)
    if (!x[i])
      for (v.push_back(i), j = i * i; j < N; j += i)
        x[j] = 1;
  while (scanf("%lld%lld%lld", &m, &a, &b), m) {
    for (p = q = i = 0; i < v.size(); ++i)
      for (j = i; j < v.size(); ++j) {
        if (a * v[j] <= v[i] * b && v[i] * v[j] <= m && v[i] * v[j] > p * q)
          p = v[i], q = v[j];
      }
    printf("%lld %lld\\n", p, q);
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool is_prime[100000];
double prime[10000];

int main() {
  memset(is_prime, 1, sizeof(is_prime));
  is_prime[0] = is_prime[1] = false;
  int p = 0;
  for (int i = 2; i < 100000; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = i * 2; j < 100000; j += i)
        is_prime[j] = false;
    }
  }
  int m;
  double a, b;
  while (scanf("%d%lf%lf", &m, &a, &b), m) {
    int Max = 0, P, Q;
    for (int i = 0; prime[i] * 2 <= m; i++) {
      int j = upper_bound(prime, prime + p, prime[i] / a * b) - prime - 1;
      int k = upper_bound(prime, prime + p, m / prime[i]) - prime - 1;
      j = min(j, k);
      if (j < 0)
        continue;
      if (Max < prime[i] * prime[j] && prime[j] / (double)prime[i] >= a / b) {
        Max = prime[i] * prime[j];
        P = prime[i];
        Q = prime[j];
      }
    }
    printf("%d %d\\n", P, Q);
  }
}

Error: TLE

Fixed submission:

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

bool is_prime[100000];
double prime[10000];

int main() {
  memset(is_prime, 1, sizeof(is_prime));
  is_prime[0] = is_prime[1] = false;
  int p = 0;
  for (int i = 2; i < 100000; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = i * 2; j < 100000; j += i)
        is_prime[j] = false;
    }
  }
  int m;
  double a, b;
  while (scanf("%d%lf%lf", &m, &a, &b), m) {
    int Max = 0, p, q;
    for (int i = 0; prime[i] * 2 <= m; i++) {
      int j = i;
      while (j >= 0 && prime[i] * prime[j] > m && prime[j] / prime[i] >= a / b)
        j--;
      if (j < 0)
        continue;
      if (Max < prime[i] * prime[j] && prime[j] / (double)prime[i] >= a / b) {
        Max = prime[i] * prime[j];
        p = prime[i];
        q = prime[j];
      }
    }
    printf("%d %d\\n", q, p);
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define intmax 101000
int isprime[intmax];
void makeprime() {
  REP(i, intmax) if (i % 2 != 0) isprime[i] = true;
  isprime[1] = false;
  isprime[2] = true;
  for (ll int i = 3; i < sqrt(intmax); i += 2) {
    for (ll int j = i + 2; j < intmax; j += 2) {
      if (j % i == 0)
        isprime[j] = false;
    }
  }
}

ll int a, b, m, p, q;

int main() {
  makeprime();
  while (1) {
    ll int c = -1;
    ll int ansp, ansq;
    cin >> m >> a >> b;
    if (m == 0)
      break;
    for (ll int p = m; p > 0; p--) {
      if (!isprime[p])
        continue;
      for (ll int q = p; q <= m / p; q++) {
        if (!isprime[q])
          continue;
        if (p * b < a * q)
          continue;
        if (c < p * q) {
          c = p * q;
          ansp = p;
          ansq = q;
        }
      }
    }
    cout << ansp << " " << ansq << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define intmax 110000
int isprime[intmax];
vector<int> primed(100000);
void makeprime() {
  REP(i, intmax) if (i % 2 != 0) isprime[i] = true;
  isprime[1] = false;
  isprime[2] = true;
  for (ll int i = 3; i < sqrt(intmax); i += 2) {
    for (ll int j = i + 2; j < intmax; j += 2) {
      if (j % i == 0)
        isprime[j] = false;
    }
  }
  FOR(i, 1, intmax) if (isprime[i]) { primed.pb(i); };
}

int main() {
  makeprime();
  int m, a, b;
  while (1) {
    cin >> m >> a >> b;
    if (m == 0 && a == 0 && b == 0)
      break;
    int q, p;
    int qpos = 0, ppos = 0;
    ll int ansp, ansq;
    ll int nowmax = -1;
    while (primed[ppos] < m) {
      p = primed[ppos];
      qpos = ppos;
      while (1) {
        if (primed[ppos] * primed[qpos] > m)
          break;
        if ((double)a / (double)b > (double)primed[ppos] / (double)primed[qpos])
          break;
        q = primed[qpos];
        if (nowmax < p * q) {
          nowmax = p * q;
          ansp = p;
          ansq = q;
        }
        qpos++;
      }
      ppos++;
    }
    cout << ansp << " " << ansq << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pi 3.141592653589793

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

int main() {
  int prime[10000];
  int cnt = 0;
  for (int i = 1; i < 10000; i++) {
    if (Isprime(i)) {
      prime[cnt] = i;
      cnt++;
    }
    // cout << i << " " << isprime[i] << endl;
  }
  int m, a, b;
  while (1) {
    cin >> m >> a >> b;
    if (m == 0)
      break;
    int answ = 0, ansh = 0;
    for (int i = 0; i < cnt; i++) {
      for (int j = i; j < cnt; j++) {
        if (prime[i] * prime[j] > m || a * prime[j] > b * prime[i])
          break;
        if (prime[i] * prime[j] > answ * ansh) {
          answ = prime[i];
          ansh = prime[j];
        }
      }
    }
    cout << answ << " " << ansh << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pi 3.141592653589793

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

int main() {
  int prime[100000];
  int cnt = 0;
  for (int i = 1; i < 100000; i++) {
    if (Isprime(i)) {
      prime[cnt] = i;
      cnt++;
    }
    // cout << i << " " << isprime[i] << endl;
  }
  int m, a, b;
  while (1) {
    cin >> m >> a >> b;
    if (m == 0)
      break;
    int answ = 0, ansh = 0;
    for (int i = 0; i < cnt; i++) {
      for (int j = i; j < cnt; j++) {
        if (prime[i] * prime[j] > m || a * prime[j] > b * prime[i])
          break;
        if (prime[i] * prime[j] > answ * ansh) {
          answ = prime[i];
          ansh = prime[j];
        }
      }
    }
    cout << answ << " " << ansh << endl;
  }
  return 0;
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  bool sosu[100010] = {1, 1, 0};
  for (int i = 2; i < 100010; i++)
    if (sosu[i] == false)
      for (int j = i * 2; j < 100010; j += i)
        sosu[j] = true;
  vi so;
  rep(i, 100010) if (sosu[i] == 0) so.pb(i);
  int a, b, c;
  while (cin >> a >> b >> c, a + b + c) {
    int oa, ob, ma = 0;
    loop(i, 2, a) if (sosu[i] == 0) {
      int t = upper_bound(all(so), a / i) - so.begin();
      t--;
      if (t == -1)
        continue;
      while (b * so[t] > i * c) {
        if (t == 0)
          break;
        t--;
      }
      if (b * so[t] <= i * c && i <= so[t]) {
        if (i * so[t] <= a && i * so[t] > ma)
          oa = i, ob = so[t], ma = i * so[t];
      }
    } // a/i b/c<=i/so[t]
    cout << oa << " " << ob << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  bool sosu[100010] = {1, 1, 0};
  for (int i = 2; i < 100010; i++)
    if (sosu[i] == false)
      for (int j = i * 2; j < 100010; j += i)
        sosu[j] = true;
  int a, b, c;
  while (cin >> a >> b >> c, a + b + c) {
    double q = (double)b / c;
    int oa, ob, ma = 0;
    loop(i, 2, a) if (sosu[i] == 0)
        loop(j, i, a) if (sosu[j] == 0 && i * j >= ma && i * j <= a &&
                          (double)i / j + 1e-8 > q) {
      oa = i;
      ob = j;
      ma = i * j;
    }
    cout << oa << " " << ob << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int M, A, B;
vector<long long> primes;
bool flgs[100001];

int main() {
  for (int i = 2; i <= 100000; i++) {
    flgs[i] = true;
  }

  for (int i = 2; i <= 100000; i++) {
    if (flgs[i]) {
      primes.push_back(i);
      for (int j = i + i; j <= 100000; j += i) {
        flgs[j] = false;
      }
    }
  }
  while (cin >> M >> A >> B, M) {
    long long a = 1;
    long long b = 1;

    for (int i = 0; i < primes.size(); i++) {
      if (primes[i] > M)
        break;
      for (int j = i; j < primes.size(); j++) {
        if (primes[i] * primes[j] > M)
          break;
        if ((primes[i] * B - primes[j] * A) >= 0 &&
            a * b < primes[j] * primes[i]) {
          a = primes[i];
          b = primes[j];
        }
      }
    }
    cout << a << " " << b << endl;
  }
}

Error: TLE

Fixed submission:

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

int M, A, B;
vector<int> primes;
bool flgs[100001];

int main() {
  for (int i = 2; i <= 100000; i++) {
    flgs[i] = true;
  }

  for (int i = 2; i <= 100000; i++) {
    if (flgs[i]) {
      primes.push_back(i);
      for (int j = i + i; j <= 100000; j += i) {
        flgs[j] = false;
      }
    }
  }
  while (cin >> M >> A >> B, M) {
    long long a = 1;
    long long b = 1;
    for (int i = 0; i < primes.size(); i++) {
      for (int j = i; j < primes.size(); j++) {
        if (primes[i] * primes[j] > M)
          break;
        if ((primes[i] * B - primes[j] * A) >= 0 &&
            a * b < primes[j] * primes[i]) {
          a = primes[i];
          b = primes[j];
        }
      }
    }
    cout << a << " " << b << endl;
  }
}