• 因数最多的数


    蒜头君对一个数的因数个数产生了兴趣,他想知
    道在1到n的范围内,因数个数最多的数是多
    少。如果有多个这样的数,他想知道最小的那
    个。
    输入格式
    第一行一个整数T.表示数据的组数。
    接下来T行,每行一个正整数n。
    1≤T≤100,1≤n≤1016
    输出格式
    -共输出T行,每行-一个正整数表示最多因数
    个数的数。
    样例输入
    10
    1 00
    1 000
    样例输出
    6
    60
    840
    \

    #include <algorithm>
    #include <iostream>
    using namespace std;
    typedef long long LL;
    int ys[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
    LL n, anx, ans;
    void dfs(int u, int m, LL cnt, LL x)
    {
        if (cnt > ans)
        {
            ans = cnt;
            anx = x;
          
        }
        else if (cnt == ans && x < anx)
        {anx = x;}
        if (u == 15)
            return;
        for (int i = 1; i <= m; i++)
        {
            x = x * ys[u];
            if ( x > n)break;
            dfs(u + 1, i, cnt*(i + 1), x);
        }
    }
    
    int main()
    {
        int t;
        cin >> t;
        while (t--)
        {
            cin >> n;
            anx = 0;
            ans = 0;
            dfs(0, 60, 1, 1);
            cout << anx << endl;
        }
    }
    
    追求吾之所爱
  • 相关阅读:
    团队开发5
    团队开发4
    团队开发3
    团队开发2
    团队开发1
    团队计划会议
    寒假学习进度---完结篇
    寒假学习进度十七
    寒假学习进度十六
    python后续学习
  • 原文地址:https://www.cnblogs.com/rstz/p/12393216.html
Copyright © 2020-2023  润新知