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 ...
随机推荐
- 原型prototype -- 深入理解javascript
/* 原型Prototype */ //一.原型 //原型使用一 var calculator = function (dlg, tax) { this.dlg = dlg; this.tax = t ...
- java mail实现Email的发送,完整代码
java mail实现Email的发送,完整代码 1.对应用程序配置邮件会话 首先, 导入jar <dependencies> <dependency> <groupId ...
- 使用Forms进行身份验证(Asp.net)
1.背景 以往项目登陆后的用户信息都是存放在session中,但session有一个问题就是读取的时候需要先实例化所在类,在调用对象()如果用static修饰,则可能到时多次登陆sessio ...
- 编写一段程序,从标准输入读取string对象的序列直到连续出现两个相同的单词或者所有单词都读完为止。使用while循环一次读取一个单词,当一个单词连续出现两次是使用break语句终止循环。输出连续重复出现的单词,或者输出一个消息说明没有人任何单词是重复出现的。
// test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- [bzoj 2159]Crash的文明世界
今天看到一个鬼题 心情好的时候写 [题意]求树上所有点对距离的k次方和,所有边权为1 大爷方的题解:http://tonyfang.is-programmer.com/posts/204972.htm ...
- SqlBulkCopy 简单运用
using(SqlConnection conn = new SqlConnection(str)) { conn.Open(); using (System.Data.SqlClient.SqlBu ...
- selenium实战脚本集——新浪微博发送QQ每日焦点(火狐)
selenium实战脚本集(1)——新浪微博发送QQ每日焦点,乙醇用谷歌实现的,下边是用火狐实现的. 代码如下: # coding = utf-8 from selenium import webdr ...
- hdu 1133 Buy the Ticket
首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1 ...
- lintcode :Segmemt Tree Build II
题目 Segmemt Tree Build II The structure of Segment Tree is a binary tree which each node has two attr ...
- 【mysql的编程专题】触发器
类似tp里面的数据模型回调接口,在数据表增删改的前或后触发执行其他的预订的sql; 一个触发器要具备4要素: 1.监视地点 -- 要执行触发器的表 2.监视事件 -- 由什么DML事件来牵引 3.触发 ...