标签:
先找出所有的数,排序,然后o(1)效率询问
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> using namespace std; long long Ans[1200000]; int tot; map<long long, int>Cun; const long long INF = 1e18; void init() { tot = 0; Cun.clear(); Cun[1] = 1; Ans[tot] = 1; } int main() { int head = 0; init(); while (1) { if (Ans[head] == 0) break; long long h = Ans[head]; if (h * 2 > INF || Cun[h * 2] == 1) {} else { tot++; Ans[tot] = h * 2; Cun[h * 2] = 1; } if (h * 3 > INF || Cun[h * 3] == 1){} else { tot++; Ans[tot] = h * 3; Cun[h * 3] = 1; } if (h * 5 > INF || Cun[h * 5] == 1) {} else { tot++; Ans[tot] = h * 5; Cun[h * 5] = 1; } if (h * 7 > INF || Cun[h * 7] == 1) {} else { tot++; Ans[tot] = h * 7; Cun[h * 7] = 1; } head++; } sort(Ans, Ans + tot + 1); int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); printf("%lld\n", Ans[n - 1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zufezzt/p/4779471.html