Codeforces 27 E Number With The Given Amount Of Divisors

来源:互联网 发布:访客网络要开启吗 编辑:程序博客网 时间:2024/06/06 14:06

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

题        意:求因子个数为n的最小数。

思        路:这道题目分析一下,1018的不大,比264要小,所以这题可以枚举。

                  一个数 A 可以分解成 p1k1 * p2k2 * …… * pnkn 其中p为素数。这样分解之后,A的因子个数S = (k1+1) *( k2+1) * …… *( kn+1)然后用dfs枚举 + 剪枝。

代码如下:

#include <iostream>using namespace std;#include <string.h>#include <stdio.h>#include <climits>#include <algorithm>typedef __int64 LL;LL ans;LL n;const LL pr[16]={2,3,5,7,11,13,17,19,23,29,31};void DFS( LL k, LL num, LL now ){    if( num > n ) return;    if( num == n && now < ans )    {        ans = now;        return;    }    for( int i = 1; i <= 64; i ++ )    {        if( now * pr[k] <= ans )           {               DFS( k+1, num*(i+1), now*=pr[k] );           }           else break;    }}const LL MAX = 1e18+9;int main(){        while( scanf ( "%I64d", &n ) != EOF )    {        ans = MAX;        DFS(0,1,1);        printf("%I64d\n",ans);    }    return 0;}

1 0