Skip to content

Instantly share code, notes, and snippets.

@psucodervn
Last active June 17, 2019 12:03
Show Gist options
  • Save psucodervn/af286e8e7e54e4f2fcc6d7548939b35c to your computer and use it in GitHub Desktop.
Save psucodervn/af286e8e7e54e4f2fcc6d7548939b35c to your computer and use it in GitHub Desktop.
MONQUA.CPP
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
void generate(int N) {
int b[] = {3, 5, 7};
int a[] = {3, 5, 7};
v.push_back(3); v.push_back(5); v.push_back(7);
for (int i = 3; i < N; ++i) {
int mx = 1e9, mj, mk;
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
int val = a[j] * b[k];
if (mx > val) {
mx = val; mj = j; mk = k;
}
}
}
v.push_back(mx);
a[mj] *= b[mk];
}
}
int solve(int n) {
return v[n - 1];
}
int main() {
generate(10000);
int nTests; cin >> nTests;
for (int t = 0; t < nTests; ++t) {
int n; cin >> n;
cout << solve(n) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment