文章目录
题目链接:
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1060
因子最多肯定是先找小的质因子,再选大的质因子,而且大的质因子的个数不会超过小的,(不然数量相同的话那我肯定选小的组成的数要小些)
#include"bits/stdc++.h"
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
const int MOD=1e9+7;
int prime[16]={ 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};//因为前16个质数乘起来就已经大于1e18了
LL N,ans,num;
void dfs(LL n,LL cnt,int k,int pre)//k是枚举的因子,从小的因子开始枚举pre表示上一次枚举了几个质因子
{
if(k==16)return ;
if((cnt>num)||(cnt==num&&n<ans))
{
num=cnt;
ans=n;
}
for(int i=1;i<=pre;i++)//这一次枚举的质因子个数一定要比上一次小
{
if(n<=N/prime[k])
{
n*=prime[k];//枚举了i个就会乘i次
dfs(n,cnt*(i+1),k+1,i);//相当于n这个数多了prime[k]^i这个因子,所以会多出:prime[k]^0,prime[k]^1,prime[k]^2....prime[k]^i,这(i+1)个因子
}
}
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>N;
ans=num=1;
dfs(1,1,0,16);
cout<<ans<<" "<<num<<endl;
}
}