题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1748、
1748. The Most Complex Number
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Let us define a
complexity of an integer as the number of its divisors. Your task is to find the most complex integer in range from 1 to
n. If there are many such integers, you should find the minimal one.
Input
The first line contains the number of testcases
t (1 ≤
t ≤ 100). The
i-th of the following
t lines contains one integer
ni
(1 ≤
ni ≤ 10
18)
.
Output
For each testcase output the answer on a separate line. The
i-th line should contain the most complex integer in range from 1 to
ni and its complexity, separated with space.
Sample
input | output |
---|---|
5 1 10 100 1000 10000 | 1 1 6 4 60 12 840 32 7560 64 |
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef unsigned long long ULL;
const ULL INF = ~0ULL;
ULL ans,n;
int best;
int p[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
void dfs(int dept,int lim,ULL tmp,int num)
{
if(tmp>n)
return ;
if(num>best){
best=num;
ans=tmp;
}
if(num==best&&tmp<ans)
ans=tmp;
for(int i=1;i<=lim;i++){//剪枝
if(n/p[dept]<tmp)
break;
dfs(dept+1,i,tmp*=p[dept],num*(i+1));
}
}
int main()
{
int cas;
cin>>cas;
while(cas--){
cin>>n;
best=0;
ans=INF;
dfs(0,60,1,1);
cout<<ans<<" "<<best<<endl;
}
return 0;
}