Codeforces 27E - Number With The Given Amount Of Divisors

来源:互联网 发布:windows cmd 切换目录 编辑:程序博客网 时间:2024/06/05 14:33

深搜枚举即可。

#include <stdio.h>int a[100] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};typedef unsigned long long ULL;int n;ULL ans;void dfs(int step, ULL tmp, int num){    if(num > n) return;    if(num == n && tmp < ans) ans = tmp;    for(int i = 1; i <= 64; i++)    {        if(ans / a[step] < tmp) break;        dfs(step + 1, tmp * a[step], num * (i + 1));        tmp *= a[step];    }}int main(){    while(~scanf("%d", &n))    {        ans = ~0ULL;        dfs(0, 1, 1);        printf("%I64u\n", ans);    }    return 0;}
0 0
原创粉丝点击