ACM/ICPC World Finals 2013 D Factors

题目大意

定义 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+1m+1i=1ai

然后我们就可以发现我们只要取前若干个质数就可以了,然后我们暴力维护每个n所对应的k( k263 ),就可以了,事实上时间也不大,一秒完全够了,后面只需要读入并把预处理出来的答案输出即可。

#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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值