timusoj 1748. The Most Complex Number (反素数&剪枝) 好题

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
5
1
10
100
1000
10000
1 1
6 4
60 12
840 32
7560 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值