快速幂
十二分热爱
这个作者很懒,什么都没留下…
展开
-
3的幂的和
求:3^0 + 3^1 +...+ 3^(N) mod 1000000007 Input 输入一个数N(0 <= N <= 10^9) Output 输出:计算结果 Input示例 3 Output示例 40 #include <bits/stdc++.h> const int mod=1000000007; using namespace st...原创 2018-07-24 19:36:40 · 173 阅读 · 0 评论 -
快速幂取模算法
算法1 int ans=1; for(int i=1;i<=b;i++) { ans=ans*a; } ans =ans%c; 可以对a关于c取余,这样可以大大减少a的大小 算法2 int ans=1; a=a%c;加上这一句 for(int i=1;i<=b;i++) { ans =ans*a; } ans=ans%c; 既然某个因子取余之后相乘再取余保持余数不变,...原创 2018-07-15 14:40:39 · 110 阅读 · 0 评论 -
A的B次幂
Description给出两个正整数A和B请输出A的B次幂结果可能很大,请对1000000007求模InputA和B,两个整数均不大于10^18OutputA的B次幂对1000000007求模Sample Input 1 2 2Sample Output 14Sample Input 2 2 10Sample Output 21024#include<iostream> #define...原创 2018-07-15 14:53:15 · 2212 阅读 · 0 评论 -
Raising Modulo (快速幂取模)
People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. ...原创 2018-08-03 09:39:56 · 159 阅读 · 0 评论 -
n^n的末位数字
给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字。 Input 一个数N(1 <= N <= 10^9) Output 输出N^N的末位数字 Sample Input 13 Sample Output 3 #include<iostream> #include<cmath> #include<string.h> ...原创 2018-10-04 20:05:57 · 405 阅读 · 0 评论