51NOD 1060 最复杂的数

把一个数的约数个数定义为该数的复杂程度,给出一个n,求1-n中复杂程度最高的那个数。
例如:12的约数为:1 2 3 4 6 12,共6个数,所以12的复杂程度是6。如果有多个数复杂度相等,输出最小的。
我们先来认识一个东西,叫反素数。
具体的这篇博文讲的很详细:http://blog.csdn.net/acdreamers/article/details/25049767
这题的话,我们可以在搜索的过程中更新,当约数的个数相同的时候,去小。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
using namespace std;
const int N=1000000;
typedef long long LL; 
int p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
LL best,ans;
LL n;
void dfs(int dept,int limit,LL tmp,LL num)
{
    if(tmp>n)
    return ;
    if(num>best)
    {
        best=num;
        ans=tmp;
    }
    if(num==best&&tmp<ans)
    {
        ans=tmp;
    }
    for(int i=1;i<=limit;i++)
    {
        double cur = (double)tmp; 
        if(n<cur*p[dept])
        break;
        dfs(dept+1,i,tmp=tmp*p[dept],num*(i+1)); 
    }   
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%I64d",&n);
        best=0;
        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、付费专栏及课程。

余额充值