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

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 10000
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
  vector<bool> Isprime(MAX + 1, true);
  vector<int> Prime(MAX + 1, 0); // Primearray
  int Primecounter = 0;          // Primearray counter;
  for (int i = 2; i < MAX + 1; i++) {
    if (Isprime[i]) {
      for (int j = 2; i * j < MAX; j++)
        Isprime[i * j] =
            false; //?´???°??????Primearray???????´??????????????????°?????¨???false???
      Prime[Primecounter] = i;
      Primecounter++;
    }
  }
  int m, a, b;
  while (cin >> m >> a >> b) {
    if (!(m + a + b))
      break;
    double dif = (double)a / (double)b;
    pii ans;
    int maxi = -INF;
    rep(i, Prime.size()) {
      if (Prime[i] * Prime[i] > m)
        break;
      for (int j = i; j < Prime.size(); j++) {
        int big = (Prime[j]);
        int mini = Prime[i];
        if (b * mini - big * a < 0)
          continue;
        if (big * mini > m)
          continue;
        if (maxi < big * mini) {
          maxi = big * mini;
          ans = pii(mini, big);
        }
      }
    }
    cout << ans.first << " " << ans.second << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.00000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
  vector<bool> Isprime(MAX + 1, true);
  vector<int> Prime(MAX + 1, 0); // Primearray
  int Primecounter = 0;          // Primearray counter;
  for (int i = 2; i < MAX + 1; i++) {
    if (Isprime[i]) {
      for (int j = 2; i * j < MAX; j++)
        Isprime[i * j] =
            false; //?´???°??????Primearray???????´??????????????????°?????¨???false???
      Prime[Primecounter] = i;
      Primecounter++;
    }
  }
  int m, a, b;
  while (cin >> m >> a >> b) {
    if (!(m + a + b))
      break;
    double dif = (double)a / (double)b;
    pii ans;
    int maxi = -INF;
    rep(i, Prime.size()) {
      if (Prime[i] > m)
        break;
      for (int j = i; j < Prime.size(); j++) {
        if (Prime[i] * Prime[j] > m)
          break;
        if ((double)max(Prime[i], Prime[j]) / (double)min(Prime[i], Prime[j]) -
                dif >=
            EPS)
          if (1 - (double)max(Prime[i], Prime[j]) /
                      (double)min(Prime[i], Prime[j]) >
              EPS)
            continue;
        if (maxi < Prime[i] * Prime[j]) {
          maxi = Prime[i] * Prime[j];
          ans = pii(min(Prime[j], Prime[i]), max(Prime[i], Prime[j]));
          //        cout<<maxi<<endl;
        }
      }
    }
    cout << ans.first << " " << ans.second << endl;
  }
}