A | The Super Powers |
|
We all know the Super Powers of this world and how they manage to get advantages in political warfare or even in other sectors. But this is not a political platform and so we will talk about a different kind of super powers – “The Super Power Numbers”. A positive number is said to be super power when it is the power of at least two different positive 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 no input.
Output
Print all the Super Power Numbers within 1 and 2^64 -1. Each line contains a single super power number and the numbers are printed in ascending order.
Sample Input | Partial Judge Output |
No input for this problem | 1 16 81 512 |
Problem Setter: Shahriar Manzoor, Special Thanks: Sohel Hafiz
题意:
如果一个数至少是两个不同的正整数的幂,那么它称为超级幂。找出1-2^64-1之间的所有超级幂。
对于x^y 如果y是合数,那么x^y一定是超级幂
然后就是枚举底数和指数即可
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
//#define WIN
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#define oform1 "%I64d"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#define oform1 "%lld"
#endif
#define S64I(a) scanf(iform, &(a))
#define P64I(a) printf(oform, (a))
#define P64I1(a) printf(oform1, (a))
#define REP(i, n) for(int (i)=0; (i)<n; (i)++)
#define REP1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FOR(i, s, t) for(int (i)=(s); (i)<=(t); (i)++)
const int INF = 0x3f3f3f3f;
const double eps = 10e-9;
const double PI = (4.0*atan(1.0));
typedef unsigned long long ULL;
int vis[100];
int heshu[100];
int sieve(int n) {
int m = (int) sqrt(n+0.5);
memset(vis, 0, sizeof(vis));
for(int i=2; i<=m; i++) if(!vis[i]) {
for(int j=i*i; j<=n; j+=i) {
vis[j] = 1;
}
}
int c = 0;
for(int i=4; i<=n; i++) if(vis[i])
heshu[c++] = i;
return c;
}
int main() {
int heshuNum = sieve(64);
int maxa = 1<<16;
set<ULL> ans;
ans.insert(1);
for(int i=2; i<maxa; i++) {
int top = ceil(64*log10(2)/log10(i));
ULL t = 1;
for(int j=1; j<top; j++) {
t *= i;
if(vis[j]) ans.insert(t);
}
}
set<ULL>::iterator it = ans.begin();
while(it != ans.end()) {
cout<<*it++<<endl;
}
return 0;
}