天天看点

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