The Super Powers

The Super Powers

以后还要记得再自己写恩!!!

/*
#include<iostream>
#include<cmath>
#include<set> 
#include<climits>
using namespace std;
typedef long long ll;
const ll maxn=1e10+1;
//素数打表和STL集合  打印所有super power数。不难发现,如果m不是素数,n^m一定是super power数。
set<long long>super;
ll prime[maxn];
void superpower()
{
    for(int i=2;i<=maxn;i++)
    if(!prime[i])
    {
        for(ll j=i+i;i<maxn;j+=i)
           prime[j]=1;
        for(ll j=pow(i,4);j<0;j*=pow(i,2))
           {
            super.insert(j);
           }
    }
}

int main()
{
    superpower();
    for(set<long long>::iterator it=super.begin();it!=super.end();++it)
       cout<<*it<<endl;
    return 0;
}
i^j<=(2^64-1)可化为j<=ln(2^64-1)/lni。(为了防爆long long,可以用double)
素数打表和STL集合  
}*/

//i^j<=(2^64-1)可化为j<=ln(2^64-1)/lni。(为了防爆long long,可以用double)
//素数打表和STL集合  打印所有super power数。不难发现,如果m不是素数,n^m一定是super power数。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;

typedef unsigned long long LL;
set<LL> table;


bool h[100];
int notPrime[100];
int top;

void calPrime()//存储非素数 (64以下的 ) 因为2^64就已经是最大的了,其他的n^64会更大
{
    for (int i = 2; i <= 64; i++)
    {
        if (!h[i])
        for (int j = i + i; j <= 64; j += i)
            h[j] = true;
        else
            notPrime[top++] = i;
    }
}

//快速幂(取模)运算   
LL powLL(LL a, int b)
{
    LL res = 1;
    while (b)
    {
        if (b & 1)//判断是不是奇数 
            res *= a;
        a *= a;
        b >>= 1;
    }
    return res;
}

int main()
{
    calPrime();

    LL maxNum = ~0ULL;//unsigned long long 类型的0  :而:~0就是这最大值 

    for (int i = 2;; i++)
    {
        LL n = maxNum;
        int t = 0;
        while (n >= i)
            n /= i, t++;// 

        if (t<4) break;//当这个n/i的次数小于四次的时候也就说明,i很大了???要溢出啦???恩对。

        for (int j = 0; j<top; j++)//top 为非素数的数量
        if (notPrime[j] <= t)//
            table.insert(powLL(i, notPrime[j]));
        //素数打表和STL集合  打印所有super power数。不难发现,如果m不是素数,n^m一定是super power数。
    }

    puts("1");//set集合里面是没有1的,输出1
    for (set<LL>::iterator it = table.begin(); it != table.end(); it++)
        printf("%llu\n", *it);//llu:无符号长整型 
    return 0;
}

这道题一开始我是不知道怎么写,然后就直接用上面的方法,感觉没有任何理由的。。。后来看别人怎么写的,,,恩这点很重要:m不是素数,n^m一定是super power数。 用了个素数打表,然后用快速幂取模,重点最后 判断 恩,什么时候截止

快速幂取模

int power(int a,int n,int m)
{
    int res=1;
    while(n){   
    if(n&1)
    {
        res*=a;
        res%=m;
    }
    a*=a;
    a%=m;
    n>>1;
}
    return res;
 } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值