题目来源:CodeForce #27 E

题目意思和题目标题一样,给一个n,求约数的个数恰好为n个的最小的数。保证答案在1018内。

Orz,这题训练的时候没写出来。

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

一个数 A 可以分解成 p1k1 * p2k2 * …… * pnkn 其中p为素数。这样分解之后,A的因子个数

S = (k1+1) *( k2+1) * …… *( kn+1)

然后用dfs枚举 + 剪枝。

剪枝的话大于现有结果return。就这样就能AC了。

附AC代码(手残,勿喷):

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#define LL __int64
namespace std;
   7:  
const LL MAX = 1e18 + 9;
const LL p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  10: LL res;
  11:  
void dfs(LL now, LL num, LL x, LL n)
  13: {
return;
if (num == n && res > now)
  16:     {
  17:         res = now;
return ;
  19:     }
int i = 1; i <= 64; i++)
if (now * p[x] > res)
break;
else
  24:             dfs(now *= p[x], num * (i+1), x+1, n);
  25: }
  26:  
int main()
  28: {
int n;
, &n))
  31:     {
  32:         res = MAX;
  33:         dfs(1, 1, 0, n);
, res); 
  35:     }
  36: }

相关文章: