0%

UVA 11752 The Super Powers (集合打表)

题目链接:
http://acm.hust.edu.cn/vjudge/contest/70017#problem/Z

题目大意:
有些数既是一个数的p次方,又是另一个数的q次方,称这样的数为Super Power,没有输入,输出所有这样的数

分析:
显而易见,满足可以写成两个以上的数不同次方的数,它的次方数必然是个合数,同时由于最小的合数是4,所以最大的底数是42641<216^4\sqrt{2^{64}-1}<2^{16}
至多65536个数,每个数至多64次幂,O(106)O(10^6),不会T
为了防止重复,最好使用集合来存数,最后用迭代器输出集合,注意循环从2开始的话需要在一开始向集合里插入一个1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 65;
ll notprime[maxn];
int tot ;
bool num[maxn];
set<ull> ans;

ull quickpow(ll a,ll n)
{
ull ans=1;
while(n)
{
if (n&1)
ans = ans * a;
a = a * a ;
n >>= 1;
}
return ans;
}


void init()
{
int i,j;
for ( int i = 2; i <= maxn ; i ++ )
if (num[i])
notprime[++tot]=i;
else
for (int j = 2 *i ; j <= maxn ; j += i )
num[j]=true;
ans.insert(1);
for (int i = 2 ; i < (1<<16);i ++)
{
int maxx = ceil(64*log(2.0)/log(i*1.0));
for (int j = 4 ; j < maxx ; j ++)
{
if (num[j])
ans.insert(quickpow(i,j));
}
}
}


int main()
{
init();
int n;
for (auto i : ans)
{
printf("%llu\n",i);
}

}