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
解题报告:打印所有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);
}