Dirichlet前缀和是求一个数所有质因子之和
而这题是求一个最小的n,使n的所有质因子之和为x(x为输入)。映射即可。
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e7 + 10;
int cnt;
int f[N];
int g[N];
bool vis[N];
int prime[N];
void init_prime(const int n) {
//素数筛
for (int i = 2; i <= n; i++) {
if (!vis[i]) {
prime[++cnt] = i;
}
for (int j = 1; j <= cnt && i <= n / prime[j]; j++) {
vis[i * prime[j]] = 1;
if (i % prime[j] == 0) {
break;
}
}
}
//狄利克雷前缀和
for (int i = 1; i <= n; i++) {
f[i] = i;
}
for (int i = 1; i <= cnt; i++) {
for (int j = 1; j * prime[i] <= n; j++) {
f[j * prime[i]] += f[j];
}
}
//映射
for (int i = 1; i <= n; i++) {
if (f[i] > n) continue;
if (g[f[i]]) continue;
g[f[i]] = i;
}
}
int main() {
init_prime(1e7);
int T; cin >> T;
while (T--) {
int n; cin >> n;
if (g[n]) cout << g[n] << endl;
else cout << -1 << endl;
}
return 0;
}