We all know the super powers ofthis world and how they manage to get advantages in political warfare or ev1_other sectors. but this is not a political platform and so we will talkabout a different kind of super powers-the super power numbers ". A positivenumber is said to be super power when it is the power of at least two differentpositive 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 (random SIVE ).
Input
This program has noinput.
Output
Print all thesuper power numbers within 1 and 2 ^ 64-1. Each line contains a single superpower 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 . . . |
Problemsetter: Shahriar Manzoor, special thanks: sohelhafiz
If a number is a super power, it must at least be the power of two different positive integers and output all values from small to large.
Idea: If this number is a super power, its index must be a combination. If we enumerate the base number first, the size is 1 ~ (1 <16), and then find the number in the range of 2 ^ 64-1
#include <iostream>#include <cstring>#include <algorithm>#include <set>#include <cstdio>#include <cmath>typedef unsigned long long ll;using namespace std;const int maxn = 100;int vis[maxn];int main() {memset(vis, 0, sizeof(vis));for (int i = 2; i < 100; i++)if (!vis[i]) {for (int j = i*i; j < 100; j += i)vis[j] = 1;}set<ll> ans;for (ll i = 2; i < (1<<16); i++) {int top = ceil(64*log10(2)/log10(i));ll tmp = 1;for (int j = 1; j < top; j++) {tmp *= i;if (vis[j])ans.insert(tmp);}}printf("1\n");set<ll>::iterator ite = ans.begin();while (ite != ans.end()) cout << *ite++ << endl;return 0;}