題目鏈接: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;
}