zoukankan      html  css  js  c++  java
  • 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;
    } 
    
    
  • 相关阅读:
    java的概述 常量 变量
    css 基础2
    css 盒子模型1
    css 基础1
    HTML 基础 3
    HTML基础2
    servletContext百科
    hibernate 一对多双向关联 详解
    hibernate generator class="" id详解
    Hibernate缓存原理与策略
  • 原文地址:https://www.cnblogs.com/NaCl/p/9580112.html
Copyright © 2011-2022 走看看