比赛 NOIP2023模拟赛5 评测结果 AAAAAAAAAAWWAAAAAWAAAW
题目名称 Number With The Given Amount Of Divisors 最终得分 82
用户昵称 ┭┮﹏┭┮ 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2023-11-17 09:39:53
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e5+10;
ll n,ans = ~1ull>>1;
int p[N],tot,v[N],f[N];
void prim(){
    for(int i = 2;i <= 10000;i++){
        if(v[i])continue;
        p[++tot] = i;
        for(int j = i;j * i <= 10000;j++)v[i*j] = 1;
    }
//    for(int i = 1;i <= tot;i++) cout<<p[i]<<' ';
//    cout<<endl;
}//埃式筛 
void fen(int x){
    int i = 1;tot = 0;
    while(x > 1){
        if(x % p[i] == 0){
            f[++tot] = p[i];
            x /= p[i];
        }
        else i++;
    }
}//分解质因数 
ll mul(ll x,int y){
    if(y == 0)return 1;
    ll s = mul(x,y/2);
    if(s * s > ans)return -1;
    if(s > ans || s == -1)return -1;
    if(y % 2)return s * s * x;
    else return s * s;
}//快速幂 
void dfs(int x,int o,ll u){
    if(u > ans)return;
    if(o == tot+1){
        ans = min(u,ans);
        return;
    }
    ll l = f[o];
    ll po = mul(p[x],l-1);
    if(po == -1 || po > ans)return;
    ull w = u * 1ull * po;
    if(w > ans)return;
    dfs(x+1,o+1,w);
    for(int i = o+1;i <= tot;i++){
        l *= f[i];
        po = mul(p[x],l-1);
        if(po > ans)return;
        w = u * 1ull * po;
        if(w > ans)return;
        dfs(x+1,i+1,w);
    }
}
int main(){
    freopen("CF27E.in","r",stdin);
    freopen("CF27E.out","w",stdout);
    scanf("%d",&n);
    if(n == 1){
        printf("1\n");
        return 0;
    }
    prim();
    fen(n);
    reverse(f+1,f+1+tot);
//    for(int i = 1;i <= tot;i++)cout<<f[i]<<' ';
//    cout<<endl;
    memset(v,0,sizeof(v));
    dfs(1,1,1);
    printf("%lld\n",ans);
    
    return 0;
}