求出所有小于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 81 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;
}