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

最小的合数是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. Ffmpeg 定位文件(seek file)

    有朋友问到ffmpeg播放文件如何定位问题,我想到应该还有一些新手朋友对这一块比较陌生.ffmpeg定位问题用到seek方法,代码 如下: void SeekFrame(AVFormatContext ...

  2. c++ std::bitset

    转载自 作用:及  64位 移位  取或  用64个位存储64个位,取 或 merge . 然后查索引即知道id是否存在~~ 目标:省空间. #include <iostream> #in ...

  3. javascript积累

    本来是java程序员,但是工作过程中总是遇到各种js的任务得完成,所以也得慢慢积累啊! 一.浏览器对象模型(Browser Object Model)BOM     window对象:当前浏览器窗口 ...

  4. Guava文档翻译之ListenableFuture

    ListenableFutureExplained 并发是一个困难的问题,但是使用强大而简单的抽象可以极大地简化并发问题.为了简化事情,Guava使用ListenableFuture继承了JDK的Fu ...

  5. select count的优化

    select count的优化 2011-08-02 12:01:36 分类: Oracle 一般情况下,select count语句很难避免走全表扫描,对于上百万行的表这个语句使用起来就比较吃力了, ...

  6. Install wget in Mac OS X Without Homebrew or MacPorts

    May 22, 2012 - 31 Comments The command line tool wget lets you retrieve a group of files from FTP an ...

  7. zoj 2777 Visible Lattice Points(欧拉函数,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<algo ...

  8. POJ 3111

    K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 5177   Accepted: 1411 Case Time ...

  9. CSS 的命名和书写

    CSS书写顺序 1.位置属性(position, top, right, z-index, display, float等) 2.大小(width, height, padding, margin) ...

  10. Web前端业界氛围极好的群——鬼懿IT

    鬼群简介 鬼懿IT主群号:,鬼懿IT-成长群:181368696 , 创建于2005年12月 ,聚集的业内人事包括:阿当,大漠,辣妈,崔凯,Rei,周裕波,司徒正美,丸子,鬼森林,寒冬,franky, ...