The Super Powers

题意: 超级数能化成两个不同的数的平方数, 例如16=2^4=4^2;

求2^64-1以内的超级数;

思路:关键一点就是任意数ans=x^n,如果n是合数,则ans是 超级数,

接下来就是枚举,很明显判定终点x^n会爆long long

所以转换成直接判定指数  i^j<2^64-1 ==>   j<ln(2^64-1)/ln (i),这样指数j从第一个合数4循环到 ln(2^64-1)/ln (i)

还有一点:一定要用unsign long long,不然超过2^63-1,会爆导致数据丢失(第一位会舍弃)

unsign long long 数据范围是0-2^64-1

long long 数据范围是-2^63到+2^63-1

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
const int N=65;
int tot=0,ans[N];
bool vis[N];
set<ll> s;

ll power(ll x,ll n)
{
    if(n==0) return 1ll;
    ll temp=power(x,n>>1);
    temp*=temp;
    if(n&1) temp*=x;
    return temp;
}

void primer()
{
    memset(vis,true,sizeof(vis));
    for(int i=2;i<N;++i)
    {
        if(vis[i]) ans[++tot]=i;
        for(int j=1;(j<=tot)&&(ans[j]*i<N);++j)
        {
            vis[i*ans[j]]=false;
            if(i%ans[j]==0) break;
        }
    }
}

int main()
{
    primer();
    s.clear();
    s.insert(1);
    double lnmax=log(pow(2.0,64.0)-1);
    for(int i=2;i<(1<<16);++i)
    {
        int maxj=(int)ceil(lnmax/log(i));
        for(int j=4;j<maxj;++j)  if(!vis[j])
        {
            ll temp=power(i,j);
            if(!s.count(temp)){
                s.insert(temp);
            }
        }

    }
    set<ll>::iterator it;
    for(it = s.begin(); it != s.end(); ++it)
        printf("%llu\n",*it);
    return 0;
}

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 264 − 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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值