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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define per(i, a, n) for (ll i = (a); i > (n); i--)
#define lep(i, a, n) for (ll i = (a); i <= (n); i++)
#define pel(i, a, n) for (ll i = (a); i >= (n); i--)
#define clr(a, b) memset((a), (b), sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9 + 7;
ll n, m, l;
string s, t;
int d[200010], dp[1010][1010];
double w[1000], v[1000];
double box[200010];
char field[200][200];

vi vec;

void hurui() {
  clr(d, 0);
  d[0] = d[1] = 1;
  for (int i = 2; i <= 100000 / 2; i++) {
    if (!d[i]) {
      vec.pb(i);
      for (int j = 2; j * i <= 100000; j++)
        d[i * j] = 1;
    }
  }
}

int main() {
  hurui();
  int x, y;
  while (1) {
    cin >> n >> m >> l;
    if (n + m + l == 0)
      break;
    x = y = 2;
    rep(i, 0, vec.sz) {
      rep(j, i, vec.sz) {
        if (vec[i] * vec[j] > n)
          break;
        if (m * vec[j] <= l * vec[i]) {
          if (x * y < vec[i] * vec[j]) {
            x = vec[i];
            y = vec[j];
          }
        } else {
          continue;
        }
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define per(i, a, n) for (ll i = (a); i > (n); i--)
#define lep(i, a, n) for (ll i = (a); i <= (n); i++)
#define pel(i, a, n) for (ll i = (a); i >= (n); i--)
#define clr(a, b) memset((a), (b), sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9 + 7;
ll n, m, l;
string s, t;
int d[200010], dp[1010][1010];
double w[1000], v[1000];
double box[200010];
char field[200][200];

vi vec;

void hurui() {
  clr(d, 0);
  d[0] = d[1] = 1;
  for (int i = 2; i <= 100000; i++) {
    if (!d[i]) {
      vec.pb(i);
      for (int j = 2; j * i <= 100000; j++)
        d[i * j] = 1;
    }
  }
}

int main() {
  hurui();
  while (1) {
    cin >> n >> m >> l;
    if (n + m + l == 0)
      break;
    int x, y;
    x = y = 0;
    double p = double(m) / double(l);
    if (p == 1) {
      rep(i, 0, vec.sz) {
        if (n < vec[i] * vec[i])
          break;
        if (vec[i] * vec[i] > x * y) {
          x = y = vec[i];
        }
      }
    } else {
      rep(i, 0, vec.sz) {
        rep(j, i, vec.sz) {
          if (vec[i] * vec[j] > n)
            break;
          if (double(double(vec[i]) / double(vec[j])) <= p)
            continue;
          if (x * y < vec[i] * vec[j]) {
            x = vec[i];
            y = vec[j];
          }
        }
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}