
数论——快速幂
文章平均质量分 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 · 1472 阅读 · 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 · 705 阅读 · 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 · 868 阅读 · 0 评论 -
Rightmost Digit(HDU-1061)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test cases. The first line of the input is a single integer T which...原创 2019-02-15 18:51:52 · 275 阅读 · 0 评论 -
Leading and Trailing(LightOJ-1282)
Problem Description You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. Input Input starts with an integer T (≤ 1...原创 2019-03-19 18:37:45 · 290 阅读 · 0 评论 -
Pupu(HDU-3003)
Problem Description There 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 · 399 阅读 · 0 评论 -
欧拉定理(洛谷-P5091)(十进制快速幂实现)
题目描述 给你三个正整数,a,m,b,你需要求:a^b mod m 输入输出格式 输入格式: 一行三个整数,a,m,b 对于全部数据: 1≤a≤10^9 1≤b≤10^{20000000} 1≤m≤10^6 输出格式: 一个整数表示答案 输入输出样例 输入样例#1: 2 7 4 输出样例#1: 2 输入样例#2: 998244353 12345 9876547210...原创 2019-08-17 10:01:21 · 384 阅读 · 0 评论