fork download
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. typedef long long LL;
  5.  
  6. LL pri[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
  7.  
  8. LL ans,n,MAXY;
  9. //求n以内因子最多的数,多个答案输出小的
  10. void dfs(LL Y,LL dep,LL num,LL limit){
  11. //因子数 深度 当前的数
  12. if(dep==16)return;
  13. //if(Y>=n)return;
  14. if(Y>MAXY)MAXY=Y,ans=num;
  15. if(Y==MAXY)ans=min(ans,num);
  16.  
  17. for(int i=1;i<=limit;i++){
  18. //因为后面的次数不会超过前面,所以这里添加上限就是一个极大的剪枝
  19. if(n/pri[dep]<num)break;//保证不超过n
  20. dfs(Y*(i+1),dep+1,num*=pri[dep],i);
  21. }
  22. }
  23.  
  24. int main(){
  25. int t;cin>>t;
  26. while(t--){
  27. scanf("%lld",&n);
  28. ans=1e18;
  29. MAXY=0;
  30. dfs(1,0,1,60);
  31. printf("%lld %lld\n",ans,MAXY);
  32. }
  33. }
  34.  
  35.  
Success #stdin #stdout 0s 5276KB
stdin
1
1000000
stdout
720720 240