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

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second
#define println(X) cout << X << endl;
#define DBG(X) cout << #X << " : " << X << endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

//??¨????????????????????????????????¨
const int MAX_PRIME = 100100;

vector<int> is_prime(MAX_PRIME, 1);
vi primes;

void calcPrime() {
  is_prime[0] = is_prime[1] = 0;
  for (int i = 2; i < MAX_PRIME; i++) {
    if (is_prime[i] == 1) {
      for (int j = i + i; j < MAX_PRIME; j += i) {
        is_prime[j] = 0;
      }
      primes.push_back(i);
    }
  }
}

int main() {
  calcPrime();
  // cout<<primes.size()<<endl;
  int m, a, b;
  while (cin >> m >> a >> b && m + a + b) {
    int p = 2, q = 2;
    for (int i = 0; i < primes.size(); i++) {
      for (int j = i; j < primes.size(); j++) {
        if ((ll)primes[i] * primes[j] > (ll)m)
          break;
        if ((double)a / b > (double)primes[i] / primes[j] + EPS)
          break;
        if ((ll)primes[i] * primes[j] > (ll)p * q)
          p = primes[i], q = primes[j];
      }
    }
    cout << p << " " << q << endl;
  }
}

Error: TLE

Fixed submission:

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second
#define println(X) cout << X << endl;
#define DBG(X) cout << #X << " : " << X << endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

//??¨????????????????????????????????¨
const int MAX_PRIME = 100100;

vector<int> is_prime(MAX_PRIME, 1);
vi primes;

void calcPrime() {
  is_prime[0] = is_prime[1] = 0;
  for (int i = 2; i < MAX_PRIME; i++) {
    if (is_prime[i] == 1) {
      for (int j = i + i; j < MAX_PRIME; j += i) {
        is_prime[j] = 0;
      }
      primes.push_back(i);
    }
  }
}

int main() {
  calcPrime();
  int m, a, b;
  while (cin >> m >> a >> b && m + a + b) {
    int p = 2, q = 2;
    for (int i = 0; i < primes.size(); i++) {
      for (int j = i; j < primes.size(); j++) {
        if ((ll)primes[i] * primes[j] > (ll)m)
          continue;
        if ((double)a / b > (double)primes[i] / primes[j] + EPS)
          continue;
        if ((ll)primes[i] * primes[j] > (ll)p * q)
          p = primes[i], q = primes[j];
      }
    }
    cout << p << " " << q << endl;
  }
}