标签:os io strong for ar art div amp
We all know the Super Powers ofthis world and how they manage to get advantages in political warfare or evenin 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 (inclusive).
Input
This program has noinput.
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 81 512 |
ProblemSetter: Shahriar Manzoor, Special Thanks: Sohel Hafiz
题意:如果一个数是超级幂的话,那么它至少是两个不同正整数的幂,从小到大输出所有
思路:如果这个数是超级幂的话,那么它的指数一定是合数,如果我们先枚举底数,大小为1~(1<<16),然后在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; }
UVA - 11752 The Super Powers,布布扣,bubuko.com
标签:os io strong for ar art div amp
原文地址:http://blog.csdn.net/u011345136/article/details/38662717