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

最小的合数是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. easyui页面布局

    html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  2. 被git extensions给坑了,Not owner 解决办法

    我只遇到这一种情况,不能访问git文件主库, 清空以前的历史文件,包括默认配置文件,重新安装一遍git extension,然后设置账号和密码, 在打开bash设置私钥和公钥 把公钥添加到你的git的 ...

  3. 2436: [Noi2011]Noi嘉年华 - BZOJ

    Description NOI2011 在吉林大学开始啦!为了迎接来自全国各地最优秀的信息学选手,吉林大学决定举办两场盛大的 NOI 嘉年华活动,分在两个不同的地点举办.每个嘉年华可能包含很多个活动, ...

  4. Linux显示中文乱码解决方法

    vi /etc/sysconfig/i18n 将内容改为 LANG="zh_CN.GB18030" LANGUAGE="zh_CN.GB18030:zh_CN.GB231 ...

  5. hdu 4888

    网络流建模,建模不难,难在找环: #include<cstdio> #include<algorithm> #include<vector> #include< ...

  6. Consumer closed input channel or an error occurred. events=0x8 channel is unrecoverably broken and will be disposed(待解决)

    跟文件读取有关?关闭文件读取试试. 有可能是读取文件 出现报错

  7. Root resource classes

    Overview A root resource class is the entry point into a JAX-RS implemented RESTful Web service. It ...

  8. Javascript操作元素属性方法总结

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  9. LR_问题_在导入wsdl时出现parsing error

    问题描述:使用LR录制webservice协议的脚本,在导入wsdl时出现parsing error,详见图 问题解决:在导入wsdl时输入的地址错误,只指定了地址的虚拟目录名称,未指定方法名称,应该 ...

  10. 银联接口(注意项&备忘)

    1,参考文档“证书下载.导出及上传流程.docx” 按照文档上所述,依次进行,导出的证书备用,用于配置文件的项“const SDK_ENCRYPT_CERT_PATH” 2,使用tp框架 新建一个控制 ...