这是一道数论题
首先我们知道,一个数的因子的个数就等于每个质因数的幂+1的积
通过这个我们可以知道。
一个数满足要求,一定要质因数的次幂是按质因数的从小到大而从大到小排序的
打个比方: 54=2*3*3
12=2*2*3
因为质因数个数是一样的,所以54不合法,只能取12
这样的话,就从小到大爆搜
传进四个参数,第1个是现在枚举到第几个质数,第2个是枚举这个数的大小
第3个是现在的第二个数的质因数的个数,第4个是上一个质因数的幂。
就这样就Ac了
谢谢oywb和liao
Code:
/**************************************************************
Problem: 1053
User: wohenshuai
Language: C++
Result: Accepted
Time:4 ms
Memory:1272 kb
****************************************************************/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
int a[30]={0,2,3,5,7,11,13,17,19,23,29,31};
LL n;
LL ans=0,num=0;
void Input()
{
scanf("%lld",&n);
}
void Dfs(int k,LL now,int cnt,int last)
{
if(k==12)
{
if(cnt>num){ans=now; num=cnt;}
if(cnt==num&&now<ans) ans=now;
return ;
}
else
{
LL t=1;
for(int i=0;i<=last;i++)
{
Dfs(k+1,now*t,cnt*(i+1),i);
t*=a[k];
if(now*t>n) break;
}
}
}
void Solve()
{
Dfs(1,1,1,60);
}
void Output()
{
printf("%lld\n",ans);
}
int main()
{
Input();
Solve();
Output();
return 0;
}