跳到正文

题解

题解:P10618 [ICPC 2013 WF] Factors

用户 1674785约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
P10618

版本

  1. v1当前

每日一刷冷门题!

C++
#include<map>
#include<cstdio>
using namespace std;
typedef __int128 i128;
const i128 INF=((i128)1<<63)-1;
int p[17]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53},c[17];
map<long long,long long>ans;
void dfs(int i,int cnt,i128 ways,i128 prod){
    if(prod>INF||i>16)return;
    if(cnt){
        long long w=ways,v=prod;
        if(!ans[w]||ans[w]>v)ans[w]=v;
    }
    i128 q=1;
    for(c[i]=0;prod*q<=INF&&c[i]<c[i-1];){
        q*=p[i],++c[i],
        ways=ways*(cnt+c[i])/c[i],
        dfs(i+1,cnt+c[i],ways,prod*q);
    }
}
int main(){
    c[0]=63,dfs(1,0,1,1);
    long long n;
    while(~scanf("%lld",&n))printf("%lld %lld\n",n,ans[n]);
}
原文