zoukankan      html  css  js  c++  java
  • 大家一起做训练 第一场 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
    ", res); 
      35:     }
      36: }
  • 相关阅读:
    Sublime text 3支持utf-8
    ubuntu17.10 安装firefox的flash
    opencv mat裁剪
    Ubuntu寻找某某库
    Ubuntu的 g++ gcc版本升降级
    Autotools知识点
    Counted(内存管理机制)
    operator new和operator delete
    STL学习笔记:空间配置器allocator
    function call操作符(operator()) 仿函数(functor)
  • 原文地址:https://www.cnblogs.com/wuhenqs/p/3400281.html
Copyright © 2011-2022 走看看