codeforces 27E Number With The Given Amount Of Divisors

E. Number With The Given Amount Of Divisors
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.

Input

The first line of the input contains integer n (1 ≤ n ≤ 1000).

Output

Output the smallest positive integer with exactly n divisors.

Examples
input
4
output
6
input
6
output
12


题意:给一个正整数n,求出满足因子数为n的最小数x(x<1e18)

刚开始想的是将n分解,6分解为2*3,答案就是2^2*3^1=12了,但是8过不了,看了别人的思路才发现完全想错了,n的范围较小,直接暴力求最小x即可



#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

#define pi acos(-1.0)
#define eps 1e-10
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))

const int inf=0x3f3f3f3f;
ull ans;
int n,p[]={0,2,3,5,7,11,13,17,19,23,29};

void dfs(ull v,int m,int o)
{
    if(m>n)return ;
    else if(m==n&&v<ans)
    {
        ans=v;
        return ;
    }
    for1(i,64)
    {
        v*=p[o];
        if(v>=ans||m*(i+1)>n)break;
        if(m<n)dfs(v,m*(i+1),o+1);
    }
}

int main()
{
    while(~sf("%d",&n))
    {
        ans=1e18;
        dfs(1ll,1ll,1ll);
        pf("%I64d\n",ans);
    }
    return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值