zoukankan      html  css  js  c++  java
  • 【搜索】n的约数

    题目链接:传送门


    【题解】:

      考察dfs和质因数分解,首先开一个prime数组。

      参数解释:

      1、当前值的大小。【利用题目的n来控制范围】

      2、控制下界,每次都是以某一个质数开始搜索, pos

      3、控制个数,每次从某一个素数的个数开始搜索。

      4、当前的值的因数个数。

    【代码】:

      

     1 #include<stdio.h>
     2 #include<algorithm>
     3 using namespace std;
     4 typedef long long ll;
     5 ll prime[ ] = { 0,2,3,5,7,11,
     6                 13,17,19,23,29,
     7                 31,37,41,43,47,
     8                 51};
     9 ll n ;
    10 int T;
    11 ll dfs( ll num , ll pos ,ll k , ll ans ){
    12     if( pos > 15 ) return 0;
    13     ll res = ans ;
    14     for(int i=1;i<=k;i++){
    15         if( n/prime[pos] < num ) break ;
    16         num *= prime[pos] ;
    17         res = max( res , dfs( num ,pos+1 , i , ans*(i+1) ) );
    18     }
    19     return res;
    20 }
    21 int main()
    22 {
    23     scanf("%d",&T);
    24     while(T--){
    25         scanf("%lld",&n);
    26         ll ans = dfs(1ll,1,64,1);
    27         printf("%lld
    ",ans);
    28     }
    29     return 0;
    30 }
    n的约数
  • 相关阅读:
    XP显示桌面
    批量改名
    poj 3126 BFS
    poj 3278 BFS
    poj 1426 BFS
    准备打酱油…
    POJ 2243 BFS 和 简单的调试方法学习
    K
    EXCEL fundamentals
    poj 1011 DFS+剪枝
  • 原文地址:https://www.cnblogs.com/Osea/p/11224527.html
Copyright © 2011-2022 走看看