UVA 11752 The Super Powers【超级幂】

时间:2023-03-10 08:02:27
UVA 11752 The Super Powers【超级幂】

题目链接:

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=111527#problem/Z

题意:

我们称一个可以由至少两个不同正整数的幂的形式表示的数为超级幂。让你找出1到264−1之间的所有超级幂。

分析:

首先ax∗y=axy,也就是说超级幂必须存在一个为合数的指数。

底数最小为2,此时指数最大为64。

指数最小为4,此时底数最小为216。

暴力枚举一发即可。

因为ull的最大值为264−1,所以乘的过程中注意判断是否大于边界。

代码:

#include <iostream>
#include<set>
#include<cstdio>
using namespace std;
const int mod = 1e9 + 7, maxn = 64 + 5;
bool isprime[maxn];
#define ull unsigned long long
ull INF = (1<<64) - 1;
set<ull>s;
void getprime()
{
int n = 64;
fill(isprime, isprime + n, 1);
for(int i = 2; i * i <= n; i++){
if(isprime[i]){
for(int j = 2 * i; j <= n; j += i){
isprime[j] = false;
}
}
}
}
int main (void)
{
getprime();
for(int i = 2; i <= 65536; i++){
ull ans = 1;
for(int j = 1; j <= 64; j++){
ans *= i;
if(!isprime[j]) s.insert(ans);
if(ans > INF / i) break;
}
}
s.insert(1);
set<ull>::iterator a;
for(a = s.begin(); a != s.end(); a++)
cout<<*a<<endl;
return 0;
}