UVA - 11752 The Super Powers

来源:互联网 发布:猴王水果竞猜源码php 编辑:程序博客网 时间:2024/05/16 19:16

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.

 

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


0 0
原创粉丝点击