题目大意
定义 f(k)=k的素因子排列数 ,给定n求 f(k)=n 的最小的k
解答
首先将k分解质因数:
k=∏i=1mpaii
很容易就可以得到:
f(k)=(∑mi=1ai)!∑mi=1ai!
对于一个新加的素数:
f(k′)=f(k)×(∑m+1i=1ai)!(∑mi=1ai)!×am+1!=f(k)×Cam+1∑m+1i=1ai
然后我们就可以发现我们只要取前若干个质数就可以了,然后我们暴力维护每个n所对应的k( k≤263 ),就可以了,事实上时间也不大,一秒完全够了,后面只需要读入并把预处理出来的答案输出即可。
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
#define LLU unsigned long long int
const LLU oo = 1ULL<<63;
LLU yh[100][100];
LLU ss[50] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67};
map<LLU, LLU> anses;
//求组合数
void preWork()
{
yh[0][0] = 1;
for (int i = 1; i <= 62; i++) {
yh[i][0] = 1;
for (int j = 1; j <= 62; j++) {
if (yh[i-1][j] <= oo && yh[i-1][j-1] <= oo)
yh[i][j] = yh[i-1][j] + yh[i-1][j-1];
else
yh[i][j] = oo;
}
}
}
//暴力搜索维护答案
void work(LLU k, LLU n, LLU count, LLU i)
{
if (count && (!anses.count(k) || anses[k] > n))
anses[k] = n;
LLU tot = 0;
LLU tmp = n;
while(ss[i] <= oo/tmp) {
tot++;
tmp *= ss[i];
work(k*yh[count+tot][tot], tmp, count+tot, i+1);
}
}
int main()
{
//freopen("factors.in", "r", stdin);
//freopen("factors.out", "w", stdout);
preWork();
work(1, 1, 0, 0);
LLU x;
while (scanf("%I64u", &x) != EOF) {
printf("%I64u %I64u\n", x, anses[x]);
}
return 0;
}