Codeforces 27E Number With The Given Amount Of Divisors (求约数个数为n的最小数)

78 篇文章 0 订阅


Number With The Given Amount Of Divisors
time limit per test:2 seconds
memory limit per test:256 megabytes

Given the number n, find the smallest positive integer which has exactlyn divisors. It is guaranteed that for the givenn 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 exactlyn divisors.

Sample test(s)
Input
4
Output
6
Input
6
Output
12

题目链接:http://codeforces.com/problemset/problem/27/E

题目大意:给一个数字n,求一个最小的数使得它的约数个数为n

题目分析:答案不超过1e18,首先假设每个素数都是一次幂,则前17个素数相乘就超出范围了,因此只需要取前16个素数,其次对于最小的素数2,2的63次方刚好是范围内的临界值,因此,只需要枚举DFS即可,三个参数pos表示当前素数,val表示当前数值,num表示当前数字约数的个数,注意几个剪枝,当val *p[pos] > ans或者约数个数已经大于n时,直接break,因为素数表是从小到大的,又因为要求约数个数恰好为n,因此如果num*(i + 1)不是n的约数,也不会得到n,就不用继续搜了

#include <cstdio>
#include <iostream>
#define ull unsigned long long
using namespace std;
ull n, ans;
int p[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

void DFS(int pos, ull val, ull num)
{
    if(num > n || pos > 15)
        return;
    if(num == n)
    {
        ans = min(ans, val);
        return;
    }
    for(int i = 1; i <= 63; i++)
    {
        if(val > ans / p[pos] || num * (i + 1) > n)
            break;
        val *= p[pos];
        if(n % (num * (i + 1)) == 0)
            DFS(pos + 1, val, num * (i + 1));
    }
    return;
}

int main()
{
    cin >> n;
    ans = 1ull << 63;
    DFS(0, 1, 1);
    cout << ans << endl;
}




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值