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;
}