
数论——快速幂
文章平均质量分 87
Alex_McAvoy
想要成为渔夫的猎手
展开
-
数论 —— 快速幂
【概述】快速幂就是利用二进制的性质来快速计算底数的 n 次幂,时间复杂度为 O(log₂N), 与朴素的 O(N) 相比效率有了极大的提高。但有时指数十分大,利用高精来写可能会超时,此时就需要十进制快速幂。【求位数公式】有时仅要求求 2 的 n 次幂的位数,这里有一个神奇的求位数公式:floor(log(2)/log(10)*n+1)double res=n*log10(2)...原创 2018-07-05 01:33:28 · 1406 阅读 · 0 评论 -
麦森数(洛谷-P1045)
题目描述形如2^{P}-1 的素数称为麦森数,这时P一定也是个素数。但反过来不一定,即如果P是个素数,2^{P}-1 不一定也是素数。到1998年底,人们已找到了37个麦森数。最大的一个是P=3021377,它有909526位。麦森数有许多重要应用,它与完全数密切相关。任务:输入P(1000<P<3100000),计算2^{P}-1 的位数和最后500...原创 2018-08-16 17:12:26 · 670 阅读 · 0 评论 -
取余运算||快速幂(洛谷-P1226)
题目描述输入b,p,k的值,求b^p mod k的值。其中b,p,k*k为长整型数。输入输出格式输入格式:三个整数b,p,k.输出格式:输出“b^p mod k=s”s为运算结果输入输出样例输入样例#1:2 10 9输出样例#1:2^10 mod 9=7源代码#include<iostream>#include<cs...原创 2018-07-05 01:53:06 · 829 阅读 · 0 评论 -
Rightmost Digit(HDU-1061)
Problem DescriptionGiven a positive integer N, you should output the most right digit of N^N.InputThe input contains several test cases. The first line of the input is a single integer T which...原创 2019-02-15 18:51:52 · 263 阅读 · 0 评论 -
Leading and Trailing(LightOJ-1282)
Problem DescriptionYou are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.InputInput starts with an integer T (≤ 1...原创 2019-03-19 18:37:45 · 260 阅读 · 0 评论 -
Pupu(HDU-3003)
Problem DescriptionThere is an island called PiLiPaLa.In the island there is a wild animal living in it, and you can call them PuPu. PuPu is a kind of special animal, infant PuPus play under the su...原创 2019-02-15 18:52:29 · 381 阅读 · 0 评论 -
欧拉定理(洛谷-P5091)(十进制快速幂实现)
题目描述给你三个正整数,a,m,b,你需要求:a^b mod m输入输出格式输入格式:一行三个整数,a,m,b对于全部数据:1≤a≤10^91≤b≤10^{20000000}1≤m≤10^6输出格式:一个整数表示答案输入输出样例输入样例#1:2 7 4输出样例#1:2输入样例#2:998244353 12345 9876547210...原创 2019-08-17 10:01:21 · 370 阅读 · 0 评论