Codeforeces 27 E Number With The Given Amount Of Divisors(反素数)

题目链接:
Codeforeces 27 E Number With The Given Amount Of Divisors
题意:
给出 n 找到最小的数使得其约数个数恰为n

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;

typedef unsigned long long lint;
const lint inf = ~0ull;
const int prime[]= {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int n;
lint ans;

void dfs(int depth, int limit, lint tmp, int num)
{
    if(num > n) return;
    if(num == n && tmp < ans) ans = tmp;
    for(int i = 1; i <= limit; ++i) { //i相当于幂次
        if(tmp * prime[depth] > ans) break; //不用扩展树的深度
        tmp *= prime[depth];
        if(n % (num * (i + 1)) == 0) { 
            dfs(depth + 1, i, tmp, num * (i + 1));
        }
    }
}

int main()
{
    while(cin >> n){
        ans = inf;
        dfs(0, 63, 1, 1);
        cout << ans << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值