UVa 11752 (素数筛选 快速幂) The Super Powers
首先有个关键性的结论就是一个数的合数幂就是超级幂。
最小的合数是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的更多相关文章
- Uva 10006 Carmichael Numbers (快速幂)
题意:给你一个数,让你判断是否是非素数,同时a^n%n==a (其中 a 的范围为 2~n-1) 思路:先判断是不是非素数,然后利用快速幂对每个a进行判断 代码: #include <iostr ...
- POJ 1845 Sumdiv [素数分解 快速幂取模 二分求和等比数列]
传送门:http://poj.org/problem?id=1845 大致题意: 求A^B的所有约数(即因子)之和,并对其取模 9901再输出. 解题基础: 1) 整数的唯一分解定理: 任意正整数都有 ...
- UVA 11609 Teams 组合数学+快速幂
In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...
- UVa 10870 Recurrences (矩阵快速幂)
题意:给定 d , n , m (1<=d<=15,1<=n<=2^31-1,1<=m<=46340).a1 , a2 ..... ad.f(1), f(2) .. ...
- UVa 11609 组队(快速幂)
https://vjudge.net/problem/UVA-11609 题意: 有n个人,选一个或多个人参加比赛,其中一名当队长,有多少种方案?如果参赛者完全相同,但队长不同,算作不同的方案. 思路 ...
- UVA Recurrences 矩阵相乘+快速幂
题目大意: f(n) = a1 f(n - 1) + a2 f(n - 2) + a3 f(n - 3) + ... + ad f(n - d),已给递推公式,求f(n)的大小. 解题思路: n很大, ...
- 快速幂模板Super
//求x^nint ans=1;while(n){ if(n&1) ans=ans*x; x*=x; n>>=1;} 快速幂就是快速算底数的n次幂.其时间复杂度为 O(logN), ...
- uva 10870 递推关系矩阵快速幂模
Recurrences Input: standard input Output: standard output Consider recurrent functions of the follow ...
- uva 10140 素数筛选(两次)
#include<iostream> #include<cstring> #include<cmath> #include<cstdio> using ...
随机推荐
- android support Percent支持库开发
Android的布局支持百分比的设置进行开发,来学习如何去实现它,不过看起来会像网页的设置,比如宽度的设置属性是`layout_widthPercent`.在此之前,我们一般都会设置Linearlay ...
- java集合类(二)List学习
接上篇 java集合类(一) List接口继承了Collection接口和Iterable接口,即同样含有Collection和 Iterable的特性,还有方法,其基本方法有: 1)有关添加: b ...
- sqlserver convert 日期时间 转换格式化
Select CONVERT(varchar(100), GETDATE(), 120): 2006-05-16 10:57:49 Select CONVERT(varchar(100), GET ...
- c++ break while
#include <iostream> #include <vector> #include <pthread.h> #include "destory_ ...
- UVA 1175 Ladies' Choice 稳定婚姻问题
题目链接: 题目 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu 问题 ...
- ORA-01031:insufficient privileges
描述:oracle11g用scott用户在plsql上以sysdba身份登录显示以上错误,可是在cmd面板中却正常,网上各种找答案不没有对症,最后这位网友的回答解决了我的问题. 原帖网址:http:/ ...
- oracle——merge
一.概述 使用merge声明从一个或者更多个表或视图中筛选记录,以用来更新或者插入到一个表或视图中.你可以指定条件以决定是执行update操作还是insert操作到目标表或视图中. 这个声明是一个 ...
- struts.properties配置详解(转)
Struts 2框架有两个核心配置文件,其中struts.xml文件主要负责管理应用中的Action映射,以及该Action包含的Result定义等.除此之 外,Struts 2框架还包含 s ...
- SOAP vs REST
Both methods are used by many of the large players. It's a matter of preference. My preference is RE ...
- POJ 2253 Frogger (求某两点之间所有路径中最大边的最小值)
题意:有两只青蛙,a在第一个石头,b在第二个石头,a要到b那里去,每种a到b的路径中都有最大边,求所有这些最大边的最小值.思路:将所有边长存起来,排好序后,二分枚举答案. 时间复杂度比较高,344ms ...