UVA 11752-The Super Powers

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

题意:这道题的意思是1个数可以被开成不同次方,那么他就是一个超级有力量的数字,也就是题目需要你去求的数字。

让你输出2^64-1以内这样的数字。题目还是很有意思的。


思路:那么现在的问题就是怎么知道一个数字可以被分成两个开方,只要自己找两个数据就可以发现, 

当一个数字满足这样的要求的时候。他的指数一定不是素数。因为他的指数可以拆分,那么底数就是变成

不同的数字,但是他的本身大小没变。

但是这题有个要注意的是,当你判断一个数字是不是越界的时候,可以使用对数来判断。

也要用无符号位的unsigned long long 这样才可以存的下 2^64-1。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
unsigned long long num[500011];
int cnt=0;
bool vis[66];
double inf,s5;
bool panduan(int x)
{
    for(int i=2; i<=x/2; i++)
        if(x%i==0)
            return 1;
    return 0;
}
void init()
{
    memset(vis,0,sizeof(vis));
    for(int i=2; i<=64; i++)
    {
        if(panduan(i))
            vis[i]=1;
    }
}
unsigned long long fp(int a,int b)
{
    unsigned long long sum=1,pow=a;
    while(b>0)
    {

        if(b&1)sum=sum*pow;
        pow=pow*pow;
        b>>=1;
    }
    return sum;
}
int main()
{
    init();
    inf=64*log(2);

    for(int i=2;i<=65535 ; i++)
    {
        unsigned long long s;
        for(int j=4; j<=63; j++)
        {
            if(!vis[j]) continue;
            s5=j*log(i);
            if(s5>inf)break;
            s=fp(i,j);

            num[cnt++]=s;
        }

    }
    sort(num,num+cnt);
    int kk=1;
    int m4=unique(num,num+cnt)-num;
   // printf("%d\n",m4);
   puts("1");
    for(int i=1;i<m4;i++)
    printf("%llu\n",num[i]);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值