首先有个关键性的结论就是一个数的合数幂就是超级幂。

最小的合数是4,所以枚举底数的上限是pow(2^64, 1/4) = 2^16 = 65536

对于底数base,指数的上限就是ceil(64*log(2)/log(base)),注意这个上限不能取到,是个开区间

 #include <cstdio>
#include <cmath>
#include <set>
#include <cassert>
using namespace std; typedef unsigned long long ULL;
typedef set<ULL>::iterator It;
bool vis[]; ULL POW(int a, int p)
{
ULL ans = , base = a;
while(p)
{
if(p & 1ULL) ans *= base;
base *= base;
p >>= ;
}
return ans;
} int main()
{
for(int i = ; i <= ; i++) if(!vis[i])
for(int j = i * i; j <= ; j += i) vis[j] = true; set<ULL> ans;
ans.insert();
for(int base = ; base < ; base++)
for(int p = ; p < (int)ceil(64.0 * log(2.0) / log(base)); p++) if(vis[p])
{
ULL v = POW(base, p);
assert(v != 1ULL); assert(v != );
if(!ans.count(v)) ans.insert(v);
} for(It i = ans.begin(); i != ans.end(); i++)
printf("%llu\n", *i); return ;
}

代码君

UVa 11752 (素数筛选 快速幂) The Super Powers的更多相关文章

  1. Uva 10006 Carmichael Numbers (快速幂)

    题意:给你一个数,让你判断是否是非素数,同时a^n%n==a (其中 a 的范围为 2~n-1) 思路:先判断是不是非素数,然后利用快速幂对每个a进行判断 代码: #include <iostr ...

  2. POJ 1845 Sumdiv [素数分解 快速幂取模 二分求和等比数列]

    传送门:http://poj.org/problem?id=1845 大致题意: 求A^B的所有约数(即因子)之和,并对其取模 9901再输出. 解题基础: 1) 整数的唯一分解定理: 任意正整数都有 ...

  3. UVA 11609 Teams 组合数学+快速幂

    In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...

  4. UVa 10870 Recurrences (矩阵快速幂)

    题意:给定 d , n , m (1<=d<=15,1<=n<=2^31-1,1<=m<=46340).a1 , a2 ..... ad.f(1), f(2) .. ...

  5. UVa 11609 组队(快速幂)

    https://vjudge.net/problem/UVA-11609 题意: 有n个人,选一个或多个人参加比赛,其中一名当队长,有多少种方案?如果参赛者完全相同,但队长不同,算作不同的方案. 思路 ...

  6. UVA Recurrences 矩阵相乘+快速幂

    题目大意: f(n) = a1 f(n - 1) + a2 f(n - 2) + a3 f(n - 3) + ... + ad f(n - d),已给递推公式,求f(n)的大小. 解题思路: n很大, ...

  7. 快速幂模板Super

    //求x^nint ans=1;while(n){ if(n&1) ans=ans*x; x*=x; n>>=1;} 快速幂就是快速算底数的n次幂.其时间复杂度为 O(logN), ...

  8. uva 10870 递推关系矩阵快速幂模

    Recurrences Input: standard input Output: standard output Consider recurrent functions of the follow ...

  9. uva 10140 素数筛选(两次)

    #include<iostream> #include<cstring> #include<cmath> #include<cstdio> using ...

随机推荐

  1. MST性质(用于构造最小生成树)

    描述:假设N=(V,{E})是一个连通网,U是顶点集V的一个非空子集.若(u,v)是一条具有最小权值(代价)的边,其中u∈U,v∈V-U,则必存在一棵包含边(u,v)的最小生成树. 证明: 假设网N的 ...

  2. [转载]C# ListView用法详解

    一.ListView类 1.常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示:只有在Details视图该属性才有意义. (2) GridLines:设 ...

  3. [设计模式] 1/2 工程与抽象工程模式 factory & Abstrac Factory

    转载 http://blog.csdn.net/wuzhekai1985 软件领域中的设计模式为开发人员提供了一种使用专家设计经验的有效途径.设计模式中运用了面向对象编程语言的重要特性:封装.继承.多 ...

  4. oracle 表空间 用户

    Oracle创建表空间.创建用户以及授权.查看权限 创建临时表空间 CREATE TEMPORARY TABLESPACE test_temp TEMPFILE 'C:\oracle\product\ ...

  5. C#委托及事件

    转载:http://www.cnblogs.com/warensoft/archive/2010/03/19/1689806.html C#委托及事件 在C#中,委托(delegate)是一种引用类型 ...

  6. [转]Java数组初始化详解

    一维数组1)   int[] a;   //声明,没有初始化 2)   int[] a=new int[5];   //初始化为默认值,int型为0 3)   int[] a={1,2,3,4,5}; ...

  7. 安装ubuntu vi编辑无法正常使用的时候 如方向键变成ABCD

    http://blog.sina.com.cn/s/blog_7e3f6e8f0100vkon.html 在使用ubuntu的时候,发现vi编辑模式下退格键backspace和上下左右光标移动键不能用 ...

  8. git的学习网站

    git官网:http://git-scm.com/ http://gitref.org/index.html http://edu.51cto.com/lesson/id-33751.html     ...

  9. linux服务器下发送邮件

    系统管理人员经常会遇到对于设备或者任务的预警与通知,通常情况有发送短信.邮件等方式.发送短信一般来说需要有短信猫(硬件)或者调用libfetion给飞信用户发送.本文介绍几种简单的发送邮件的方式. 本 ...

  10. Hibernate逍遥游记-第12章 映射值类型集合-001映射set(<element>)

    1. 2. <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate ...