The Super Powers

A

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 Input                              

Partial Judge Output

No input for this problem   

 

1

16
64

81
256

512
.
.
.



寻找1-2的64次幂-1中,可以表示成两个以上不同底数的整数次幂,通过分析可以发现,只要指数是合数就满足条件,因此只要枚举指数和底数即可,由于数较大,所以要用unsigned long long ,运用换底公式,注意向上取整的方法,避免精度损失。

#include<iostream>
#include<cmath>
#include<set>
using namespace std;
#define maxn 90
#define dp(c) ceil(64/(log(c)/log(2)))-1//ceil取整,返回大于等于指定表达式的最小整数,b<(64/(log(a)/log(2))),当后者为整数时,b=(64/(log(a)/log(2)))-1;
//当后者为小数时,b=int((64/(log(a)/log(2)))),即为取整后者向下取整,综上知,b为向上取整在减一


int flag[maxn];
set<unsigned long long >se;//定义容器的存储的数据类型为ull用来存储大数
void intial(){//素数打表
    int d=sqrt(90);
    for(int i=2;i<=d;i++){
        for(int j=i*i;j<=90;j+=i){
            if(!flag[j]) flag[j]=1;
        }
    }
    flag[1]=1;
    flag[0]=1;
}
unsigned long long fact(int a,int b){//编写计算高幂的函数
    unsigned long long sum=1;
    for(int i=0;i<b;i++){
        sum=sum*a;
    }
    return sum;
}


int main(){
    cout<<1<<endl;
    se.clear();
     intial();
   for( long long i=2;i<fact(2,16);i++){
        for(int j=4;j<=dp(i);j++){
            if(flag[j]) se.insert(fact(i,j));
        }
    }
   set<unsigned long long >::iterator it=se.begin();
   while(it!=se.end()){
    cout<<(*it)<<endl;
    it++;
   }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值