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 264 − 1. Each line contains a single super power number and the numbers are printed in ascending order.
Note: Remember that there are no input for this problem. The sample output is only a partial solution.
Sample Input
Sample Output
1
16
64
81
256
512
.
.
.
#include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <cstdio> #include <vector> #include <map> #include <cstdlib> using namespace std; typedef unsigned long long ull; vector<ull> ans; int limit[100007]; bool prime[100007]; const ull maxn=-1; int main() { // freopen("D:\\Administrator\\Desktop\\1.txt","w",stdout); for(int i=4;i<64;i++) { for(ull j=1;j<=maxn;j++) { ull x=1,mm; int f=0; for(int k=0;k<i-1;k++) { x*=j; mm=x*j; if(x==0||mm%x!=0||mm/x!=j) { f=1; break; } } if(f) { limit[i]=j; break; } } } for(int i=2;i<=64;i++) if(!prime[i]) { for(int j=2*i;j<=64;j+=i) prime[j]=true; } for(int i=4;i<64;i++) { if(prime[i]) { for(int j=2;j<limit[i];j++) { ull x=1; for(int k=0;k<i;k++) x*=j; ans.push_back(x); } } } ans.push_back(1); sort(ans.begin(),ans.end()); ans.erase(unique(ans.begin(),ans.end()),ans.end()); for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl; return 0; }