反素数The Most Complex Number 搜索+剪枝

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1748

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

题意:给定一个数n  求0~n  中约数最多的数 输出者个数及其约数个数  由于数据比较大 需要剪枝

#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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值