恰好有N个因子的最小正整数M

#include <cstdio>
#include <algorithm>
#include <cmath>K

int tmp[1000], cnt, rec[1000];
int prime[30] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 39, 41, 43, 47};
double ans, LOG[30];

void DFS(int pos, int val, int MAX, double clog) {
    if (clog > ans) return;
    if (val == 1) {
        cnt = pos;
        ans = clog;
        for (int i = 1; i < pos; i++)
            rec[i] = tmp[i];
        return;
    }

    for (int i = 1; i * i <= val && i <= MAX; i++) {
        if (val % i == 0) {
            if (i != 1) {
                tmp[pos] = i;
                DFS(pos+1, val/i, i, clog + LOG[pos] * (i-1));
            }
            if (val / i <= MAX && val / i != i) {
                tmp[pos] = val/i;
                DFS(pos+1, i, val/i, clog + LOG[pos] * (val/i - 1));
            }
        }
    }
}

int main() {
    int N;
    for (int i = 0; i < 16; i++)
        LOG[i] = log((double)prime[i]);
    while (scanf("%d", &N) != EOF) {
        ans = 0x3f3f3f3f;
        DFS(1, N, N, 0);
        long long M = 1;
        for (int i = 1; i < cnt; i++)
            for (int j = 1; j < rec[i]; j++)
                M *= prime[i];
        printf("%lld\n", M);
    }
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰阔落

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值