uva 11752 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 = 8 2 and
64 = 4 3 . You have to write a program that lists all super powers within 1 and 2 64 − 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.
Note: Remember that there are no input for this problem. The sample output is only a partial solution.
Sample Input
Sample Output
1
16
64
81
256
512
.
.
.
中文:
找出所有1到2^64-1的范围当中的一个数,这个数可以表示为a^x和b^y。没有输入

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int p[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
int vis[70];
const ull maxn=(2<<64)-1;
set<ull> ans;

int main()
{
    ios::sync_with_stdio(false);
    ans.insert(1);
    for(int i=0;i<18;i++)
        vis[p[i]]=1;
    for(ull i=2;;i++)
    {
        ull tmp=maxn;
        int ind=-1;
        while(tmp)
        {
            tmp/=i;
            ind++;
        }
        if(ind<4)
            break;
        tmp=i;
        for(ull j=2;j<=ind;j++)
        {
            tmp*=i;
            if(!vis[j])
                ans.insert(tmp);
        }
    }
    for(auto x:ans)
        cout<<x<<endl;

    return 0;
}

解答:
只要找出一个数,让他的次幂数是一个合数即可。但是程序没写出来,看别人题解明白了。每次都用2^64-1不断去除一个数,除了多少次,就是这个数的次幂数。放入set中去重即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值