CodeForces 27 E.Number With The Given Amount Of Divisors(dfs)

本文介绍了一种算法,用于寻找具有指定数量因子的最小正整数,并提供了一个具体的C++实现示例,该算法通过限制搜索范围来提高效率。

Description

给出一整数n,求有n个因子的最小正整数,保证答案不会超过1018

Input

一个正整数n(1n1000)

Output

输出有n个因子的最小正整数

Sample Input

4

Sample Output

6

Solution

答案不超过1018,直接对前十几个素因子暴搜即可

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=101;
int n,p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
ll ans;
void dfs(int pos,int tn,ll tans)
{
    if(n==tn)
    {
        ans=min(ans,tans);
        return ;
    }
    for(int i=1;i<=60;i++)
    {
        if(tn*(i+1)>n||tans*p[pos]>ans)break;
        tans*=p[pos]; 
        dfs(pos+1,tn*(i+1),tans);
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        ans=1e18;
        dfs(0,1,1);
        printf("%I64d\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值