You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
2 years ago
#define int long long
#define endl "\n"
2 years ago
const int N = 100010;
2 years ago
2 years ago
// 筛法求莫比乌斯函数(枚举约数)
2 years ago
int mu[N];
2 years ago
int primes[N], cnt;
bool st[N];
void get_mobius(int n) {
2 years ago
mu[1] = 1;
2 years ago
for (int i = 2; i <= n; i++) {
if (!st[i]) {
primes[cnt++] = i;
2 years ago
mu[i] = -1;
}
2 years ago
for (int j = 0; primes[j] <= n / i; j++) {
int t = primes[j] * i;
st[t] = true;
if (i % primes[j] == 0) {
mu[t] = 0;
2 years ago
break;
}
2 years ago
mu[t] = -mu[i];
2 years ago
}
}
2 years ago
}
2 years ago
int check(int mid, int k) {
2 years ago
int res = 0;
2 years ago
for (int i = 1; i * i <= mid; i++) // 枚举范围内每个平方数
res += mu[i] * (mid / i / i);
2 years ago
return res >= k;
2 years ago
}
2 years ago
signed main() {
2 years ago
// 获取莫比乌斯函数值
2 years ago
get_mobius(N - 1);
2 years ago
int T, k;
cin >> T; // T组测试数据
while (T--) {
cin >> k; // 第k个数
int l = 1, r = 2e9;
2 years ago
while (l < r) {
2 years ago
int mid = l + r >> 1;
2 years ago
if (check(mid, k))
r = mid;
2 years ago
else
2 years ago
l = mid + 1;
2 years ago
}
2 years ago
cout << r << endl;
2 years ago
}
}