VJ C - Prime Gift test6 RE求调

题目
code:

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 17, M = 5e6+1;
int n, k;
struct Product {
	int p[N], pro[M], sz, t;
	void init(char op) {
		if (op == 'l') sz = n>>1;
		if (op == 'r') sz = n+1>>1;
		memset(pro, 0, sizeof pro);
		memset(p, 0, sizeof p);
		t = 0;
	}
	void read() {
		for (int i = 1; i <= sz; ++i)
			cin >> p[i];
	}
	void get_pro(int k, int prod) {
		pro[++t] = prod;
		if (k == sz+1) return ;
		for (int i = 1; i < 1e18/prod; i *= p[k])
			get_pro(k+1, prod*i);
	}
	void arrange_pro() {
		sort(pro+1, pro+t+1);
		t = unique(pro+1, pro+t+1)-pro-1;
	}
}L, R;

bool check(int key) {
	int res = 0;
	for (int i = 1, j = R.t; i <= L.t; ++i) {
		for (; j && R.pro[j] > key/L.pro[i]; --j);
		res += j;
	}
	return res >= k;
}
int solve(int l, int r) {
	while (l < r) {
		int mid = l+r>>1;
		if (check(mid)) r = mid;
		if (!check(mid)) l = mid+1;
	}
	return r;
}

signed main() {
	cin >> n;
	L.init('l'), R.init('r');
	L.read(), R.read();
	L.get_pro(1, 1), R.get_pro(1, 1);
	L.arrange_pro(), R.arrange_pro();
	cin >> k; cout << solve(0, 1e18);
	return 0;
}