Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define FOR(v, c) for (auto &v : c)

#define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end()

#define PB(n) push_back(n)
#define MP(a, b) make_pair((a), (b))
#define EXIST(c, e) ((c).find(e) != (c).end())

#define fst first
#define snd second

#define DUMP(x) cerr << #x << " = " << (x) << endl
#define DEBUG(x)                                                               \\
  cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl

// eratosthenes の篩（素数かどうかの表が返る）
vector<bool> eratosthenes(int n) {
  vector<bool> nums(n + 1, true);
  nums[0] = nums[1] = false;

  for (int i = 0; i < nums.size(); ++i) {
    if (!nums[i]) {
      continue;
    }

    for (int j = 2; i * j < nums.size(); ++j) {
      nums[i * j] = false;
    }
  }

  return nums;
}

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

  VI primes;
  {
    vector<bool> isPrime(eratosthenes(100000));
    REP(i, 2, isPrime.size()) {
      if (isPrime[i]) {
        primes.PB(i);
      }
    }
  }

  while (true) {
    int m, a, b;
    cin >> m >> a >> b;

    if (!(m | a | b)) {
      break;
    }

    int p, q, maxmul = 0;
    REP(i, 0, primes.size()) {
      if (m < primes[i]) {
        break;
      }

      REP(j, 0, primes.size()) {
        if (m < primes[i] * primes[j]) {
          break;
        }
        if (maxmul < primes[i] * primes[j] &&
            1. * a / b <= 1. * primes[i] / primes[j] &&
            1. * primes[i] / primes[j] <= 1) {
          maxmul = primes[i] * primes[j];
          p = primes[i];
          q = primes[j];
        }
      }
    }

    cout << p << ' ' << q << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define FOR(v, c) for (auto &v : c)

#define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end()

#define PB(n) push_back(n)
#define MP(a, b) make_pair((a), (b))
#define EXIST(c, e) ((c).find(e) != (c).end())

#define fst first
#define snd second

#define DUMP(x) cerr << #x << " = " << (x) << endl
#define DEBUG(x)                                                               \\
  cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl

// eratosthenes の篩（素数かどうかの表が返る）
vector<bool> eratosthenes(int n) {
  vector<bool> nums(n + 1, true);
  nums[0] = nums[1] = false;

  for (int i = 0; i < nums.size(); ++i) {
    if (!nums[i]) {
      continue;
    }

    for (int j = 2; i * j < nums.size(); ++j) {
      nums[i * j] = false;
    }
  }

  return nums;
}

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

  VI primes;
  {
    vector<bool> isPrime(eratosthenes(100000));
    REP(i, 2, isPrime.size()) {
      if (isPrime[i]) {
        primes.PB(i);
      }
    }
  }

  while (true) {
    int m, a, b;
    cin >> m >> a >> b;

    if (!(m | a | b)) {
      break;
    }

    int p, q, maxmul = 0;
    REP(i, 0, primes.size()) {
      REP(j, 0, primes.size()) {
        if (maxmul < primes[i] * primes[j] && primes[i] * primes[j] <= m &&
            1. * a / b <= 1. * primes[i] / primes[j] &&
            1. * primes[i] / primes[j] <= 1) {
          maxmul = primes[i] * primes[j];
          p = primes[i];
          q = primes[j];
        }
      }
    }

    cout << p << ' ' << q << endl;
  }

  return 0;
}