1748. The Most Complex Number
Time limit: 1.0 second
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 |
5110100100010000 | 1 16 460 12840 327560 64 |
Problem Author: Petr Lezhankin
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
const ll INF= (ll)1<<63;
int m;
ll ans,n;
int p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
void dfs(int gen,int mm,ll tmp,int num)//加上剪枝,省时。
{
if(tmp>n)
return ;
if(num>m)
{
m=num;
ans=tmp;
}
if(num==m&&ans>tmp)
ans=tmp;
for(int i=1;i<=mm;i++)
{
double cc=(double)tmp;
if(n<cc*p[gen])
break;
dfs(gen+1,i,tmp*=p[gen],num*(i+1));
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
ans=INF;
m=0;
dfs(0,60,1,1);
printf("%lld %d\n",ans,m);
}
return 0;
}