zoukankan      html  css  js  c++  java
  • soj1201- 约数

    1201: 约数

    Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 14  Solved: 4 [Submit][Status][Web Board]

    Description

    我们定义F(n)为n的约数个数(包含1和它本身),例如F(6)=4;

    求F(n)想必大家都会,今天UnkelTao想知道的是,[1=<i<=n]最大的F(i)是多少呢?

    Input

    输入第一行为数据组数 T(T <= 100)。

    对于每组数据,只有一个数字 n(1 <= n <= 10^9)

    Output

    对于每组数据,请在一行中输出两个数,即i [1, n]中最大的F(i)输出iFi);用一个空格隔开,如果有相同的F(i)输出最小的i。格式见样例。如果使用大数,请用long long而非__int64;(long long大小为10^18次方左右)输入输出则使用(sacnf("%lld",&n)printf("%lld",n); 或者cincout

    Sample Input

    3
    10
    20
    30
    

    Sample Output

    6 4
    12 6
    24 8
    

    解法:
    #include<cstdio>
    #include<cmath>
    #include<iostream>
    #include<cstring>
    using namespace std;
    long long ss[10]={2,3,5,7,11,13,17,19,23,29};
    long long n,da[10],ans,xxx;
    int js() //计算当前状态下枚举出的数字的因子个数
    {
        int i;
        long long tot=1;
        for (i=0;i<10;i++)
        {
            if (da[i]==0) break;
            tot*=(da[i]+1);
        }
        return tot;
    }
    void search(int x,int tot) //由素数表枚举数
    {
        long long tt,t;
        t=tot;
        if (tot*ss[x]>n)
        {
            tt=js();
            if (tt>ans){ans=tt;xxx=tot;}
            if (tt==ans)
                if (tot<xxx) xxx=tot;
            return;
        }
        while (1)
        {
            t*=ss[x];
            if (t>n) break;
            da[x]++;
            search(x+1,t);
        }
        da[x]=0;
    }
    int main()
    {
        int ttt,ll;
        long long x,t;
        cin>>ttt;
        for (ll=1;ll<=ttt;ll++)
        {
            cin>>n;
            if (n==1){cout<<"1 1"<<endl;continue;}
            memset(da,0,sizeof(da));
            ans=0;
            search(0,1);
            cout<<xxx<<" "<<ans<<endl;
        }
    }
     
  • 相关阅读:
    Android Stuido无法下载jcenter库
    android studio的Gradle一直在sync的办法
    mysql dual表的用途及案例
    编码-解码
    循环神经网络RNN
    项目中遇到的chrome 浏览器跨域方案
    angular 不同组件间通过service传递数据
    angular -moment.js瘦身
    windows10电脑共享文件问题记录
    解决vue本地构建热更新卡顿的问题“75 advanced module optimization”解决方案
  • 原文地址:https://www.cnblogs.com/mbcxm/p/3187278.html
Copyright © 2011-2022 走看看