算法
(数论)
注意到 $n \leqslant d(n) = c \leqslant 1e7$,所以直接筛出 $c$ 即可。
C++ 代码
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < (t); ++i)
#define drep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define dsrep(i, t, s) for (int i = (t) - 1; i >= (s); --i)
using std::cin;
using std::cout;
using ll = long long;
const int N = 1e7 + 10;
int pf[N];
ll d[N];
int ans[N];
void init() {
std::memset(pf, -1, sizeof pf);
pf[1] = 1;
for (int i = 2; i * i < N; ++i) {
if (pf[i] == -1) {
pf[i] = i;
for (int j = i * i; j < N; j += i) {
if (pf[j] == -1) pf[j] = i;
}
}
}
d[1] = 1;
srep(i, 2, N) {
if (pf[i] == -1) {
pf[i] = i;
d[i] = i + 1;
}
else {
int x = i;
d[i] = 1;
while (x % pf[i] == 0) {
x /= pf[i];
d[i] = d[i] * pf[i] + 1;
}
d[i] *= d[x];
}
}
std::memset(ans, -1, sizeof ans);
dsrep(i, N, 1) {
if (d[i] < N) ans[d[i]] = i;
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
init();
int t;
cin >> t;
while (t--) {
int c;
cin >> c;
cout << ans[c] << '\n';
}
return 0;
}