UVA11752 The Super Powers 素数筛选

求出所有小于2^64-1的Super Powers

一个数n是Super Powers当 a^i=b^j=n

很显然,super powers的幂指数一定是和数,素数筛选找出小于64的所有和数,然后枚举底数在2到1<<16范围之内,因为最小合数4

注意1是一个特殊的数,直接输出。

另外·溢出判断要注意ceil(64/(log(a)/log(2)))-1这是对于a这个底数而言,最高的不溢出的幂。



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
.
.
.


Problem Setter: Shahriar Manzoor, Special Thanks: Sohel Hafiz

 

#include<iostream>
#include<cmath>
#include<cstdio>
#include<set>
#include<iterator>
#include<cstring>
#include<string>
#include<cstdlib>

using namespace std;

typedef unsigned long long ULL;
#define INF 18446744073709551615
#define top(a) ceil(64/(log(a)/log(2)))-1
bool vis[90];
set<ULL> s;
set<ULL>::iterator si;

void sieve(int n)
{
    int m=sqrt(n+0.5);
    memset(vis,0,sizeof(vis));
    for(int i=2;i<=m;i++) if(!vis[i])
        for(int j=i*i;j<=n;j+=i) vis[j]=1;
}

int main()
{
    sieve(80);
    s.clear();
    cout<<"1"<<endl;
    for(ULL i=2;i<(1<<16);i++)
    {
        int tp=top(i);
        ULL num=i;
        for(int j=2;j<=tp;j++)
        {
            num*=i;
            if(!vis[j]) continue;
            if(s.count(num)==0) s.insert(num);
        }
    }
    si=s.begin();
    while(si!=s.end())
        cout<<*si++<<endl;
    return 0;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值