大家一起做训练 第一场 E Number With The Given Amount Of Divisors

题目来源: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代码(手残,勿喷):

   1: #include <iostream>
   2: #include <cstdio>
   3: #include <cmath>
   4: #include <cstdlib>
   5: #define LL __int64
   6: using namespace std;
   7:  
   8: const LL MAX = 1e18 + 9;
   9: const LL p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  10: LL res;
  11:  
  12: void dfs(LL now, LL num, LL x, LL n)
  13: {
  14:     if (num > n) return;
  15:     if (num == n && res > now)
  16:     {
  17:         res = now;
  18:         return ;
  19:     }
  20:     for (int i = 1; i <= 64; i++)
  21:         if (now * p[x] > res)
  22:             break;
  23:         else
  24:             dfs(now *= p[x], num * (i+1), x+1, n);
  25: }
  26:  
  27: int main()
  28: {
  29:     int n;
  30:     while(~scanf("%d", &n))
  31:     {
  32:         res = MAX;
  33:         dfs(1, 1, 0, n);
  34:         printf("%I64d\n", res); 
  35:     }
  36: }

转载于:https://www.cnblogs.com/wuhenqs/p/3400281.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值