UVa 11752 - The Super Powers (数论)

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
64

81
256

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





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值