51nod 四级题 汇总

51Nod-1060-最复杂的数

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
const ull INF = ~0ull;
int Num;
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 dep, ull tmp, int num, int pre)
{
    if(dep >= 16) return ;
    if(tmp > n) return ;
    if(num > Num) {
        Num = num;
        ans = tmp;
    }
    else if(num == Num && tmp < ans)
        ans = tmp;
    for(int i=1;i<=pre;i++) {
        if(n/p[dep] < tmp) break;
        dfs(dep+1, tmp*=p[dep], num*(i+1), i);
    }
}

int main()
{
    int T; scanf("%d", &T);
    while(T--) {
        scanf("%llu", &n);
        ans = INF;
        Num = 0;
        dfs(0,1,1,20);
        printf("%llu %d\n", ans, Num);
    }
    return 0;
}
搜索 + 剪枝

 

posted @ 2018-11-28 17:04  Draymonder  阅读(148)  评论(0编辑  收藏  举报