题目大意
给出n,问小于n的数中,因数最多的数
解题思路
要满足因数最多,则小的质因数个数要大于等于打的质因数个数
那么直接按这个需求dfs枚举每个质因数的指数
code
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll T,x,now,ans;
ll b[]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
void dfs(ll x,ll dep,ll nw,ll as,ll las)
{if(as*x<ans)return;if(x<b[dep]){if(as>ans||as==ans&&nw<now)ans=as,now=nw;return;}ll g=1,gg=1;while(x>=b[dep]&&g<las){x/=b[dep];gg*=b[dep];g++;dfs(x,dep+1,nw*gg,as*g,g);}return;
}
int main()
{scanf("%lld",&T);while(T--){now=ans=1;scanf("%lld",&x);dfs(x,1,1,1,100);printf("%lld %lld\n",now,ans);}return 0;
}