• UVA-11752 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 2^64 -1. Each line contains a single super power number and the numbers are printed in ascending order.

    Sample Output

    1

    16

    64

    81

    256

    512

    .

    .

    .

    题意:求超级幂。一个数n能表示成ai^bi,a,b至少存在两组时,n为超级幂。输出2^64-1内的所有超级幂。

    解析:底数在[2,1<<16]内,指数是64以内的合数。底数为a的幂不会溢出的上限为ceil(64/((log(a)/log(2)))-1。

    一开始以为底数应该是素数,导致wa了很多次。

    代码如下:

    # include<iostream>
    # include<cstdio>
    # include<cstring>
    # include<set>
    # include<vector>
    # include<cmath>
    # include<algorithm>
    using namespace std;
    const int N=105;
    int vis[N];
    unsigned long long mypow(int a,int b)
    {
        if(b==0)
            return 1;
        if(b==1)
            return a;
        unsigned long long res=mypow(a,b>>1);
        res*=res;
        if(b&1)
            res*=a;
        return res;
    }
    void get_prim()
    {
        int i,j;
        fill(vis,vis+N,0);
        for(i=2;i<N;++i){
            if(vis[i])
                continue;
            for(j=i+i;j<N;j+=i)
                vis[j]=1;
        }
    }
    int main()
    {
        int i,j;
        get_prim();
        set<unsigned long long>s;
        s.insert(1);
        set<unsigned long long>::iterator it;
        for(i=2;i<(1<<16);++i){
            for(j=4;j<=ceil(64/(log(i)/log(2)))-1;++j){
                if(vis[j]){
                    s.insert(mypow(i,j));
                }
            }
        }
        for(it=s.begin();it!=s.end();++it)
            printf("%llu ",*it);
        return 0;
    }

  • 相关阅读:
    2.vue插件总结——总有你能用上的插件
    1.前端数据可视化插件:Highcharts、Echarts和D3(区别)
    git学习地址
    node vue 微信公众号(四)配置环境 本地测试
    解决element 分页组件,搜索过后current-page 绑定的数据变了,但是页面当前页码并没有变的问题
    导入excel并进行数据提取
    后端返回字符串中带换行符,前端需转换
    正则表达式tab表示
    FormData
    interval
  • 原文地址:https://www.cnblogs.com/20143605--pcx/p/4668501.html
Copyright © 2020-2023  润新知