Uva 11752 The Super Powers 解题报告(数学)

本文介绍了一种算法,用于找出1到2^64-1范围内的所有超级幂次数(superpower numbers)。超级幂次数是指至少由两个不同正整数的幂次表达的正整数。文中提供了一个具体的实现方案,包括主要的数据结构和算法步骤。
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
.
.
.


Problem Setter: Shahriar Manzoor, Special Thanks: Sohel Hafiz


    解题报告:打印所有super power数。不难发现,如果m不是素数,n^m一定是super power数。这样直接遍历,保存在set里就好了。另外记得打印1。代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;

typedef unsigned long long LL;
set<LL> table;
set<LL>::iterator it;

bool h[100];
int notPrime[100];
int top;

void calPrime()
{
    for(int i=2;i<=64;i++)
    {
        if(!h[i])
            for(int j=i+i;j<=64;j+=i)
                h[j]=true;
        else
            notPrime[top++]=i;
    }
}

LL powLL(LL a,int b)
{
    LL res=1;
    while(b)
    {
        if(b&1)
            res*=a;
        a*=a;
        b>>=1;
    }
    return res;
}

int main()
{
    calPrime();

    LL maxNum = ~0ULL;

    for(int i=2;;i++)
    {
        LL n=maxNum;
        int t=0;
        while(n>=i) n/=i,t++;

        if(t<4) break;

        for(int j=0;j<top;j++) if(notPrime[j]<=t)
            table.insert(powLL(i, notPrime[j]));
    }

    puts("1");
    for(it=table.begin();it!=table.end();it++)
        printf("%llu\n",*it);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值