zoukankan      html  css  js  c++  java
  • uva11752(The Super Powers) 暴力枚举

    We all know the Super Powers of this world and how they manage to get advantages in political warfare or even in other sectors. But this is not a political platform and so we will talk about a different kind of super powers — “The Super Power Numbers”. A positive number is said to be super power when it is the power of at least two different positive integers. For example 64 is a super power as 64 = 82 and 64 = 43 . You have to write a program that lists all super powers within 1 and 264 − 1 (inclusive).

    Input

    This program has no input. Output Print all the Super Power Numbers within 1 and 264 − 1. Each line contains a single super power number and the numbers are printed in ascending order. Note: Remember that there are no input for this problem. The sample output is only a partial solution. Sample Input Sample

    Output

    1

    16

    64

    81

    256

    512

    ......

    分析:题目让你打出区间[1,264-1]的所有超级幂。如果一个数是超级幂,

    那么它能表示成至少两个不同数的幂形式。

    容易知道只有幂是合数才能拆分,这段区间中最小的数为2(1为特殊情况),最大的幂为64,

    所以把1到64所有的合数选出来,再枚举底数,因为最小的合数为4,所以最大的底数为216

    因此枚举2~216 的底数就可以了,注意先用对数判断一个数是否大于264-1就可以了。

    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    double M=log10(18446744073709551615.0);
    using namespace std;
    int e[45]={4,6,8,9,10,12,14,15,16,18,20,21,22,24,25,26,27,28,30,32,33,34,35,36,38,39,40,42,44,45,46,48,49,50,51,52,54,55,56,57,58,60,62,63,64};
    unsigned long long Pow(unsigned long long x,int k)
    {
        if(k==1) return x;
        unsigned long long y=Pow(x,k/2);
        y*=y;
        if(k%2) y*=x;
        return y;
    }
    
    unsigned long long ans[100000];
    int main()
    {
        int N=1;
        for(int i=2;i<65536;i++)
        {
            int flag=1;
            for(int j=0;j<45;j++)
            {
                if((double)(e[j]*1.0)*log10(i)>M) break;
                unsigned long long temp=Pow(i,e[j]);
                ans[N++]=temp;
                flag=0;
            }
            if(flag) break;
        }
        printf("1
    ");
        sort(ans+1,ans+N);
        for(int i=1;i<N;i++)
        if(ans[i]!=ans[i-1]) printf("%llu
    ",ans[i]);
        return 0;
    }
    View Code
  • 相关阅读:
    【Redis】搭建主从复制
    【安装】Ubuntu之Docker
    【安装】Ubuntu之MySQL
    【Docker】Dockerfile构建指令
    【Docker】常用命令
    【14】Flask 请求上下文
    【13】Flask 上下文前夕
    【12】Flask 分析线程和协程
    【11】Flask 高级进阶
    【10】Flask 高级摘要
  • 原文地址:https://www.cnblogs.com/ACRykl/p/8626370.html
Copyright © 2011-2022 走看看