51nod 1031(快速幂)
来源:互联网 发布:盐城大数据产业园 编辑:程序博客网 时间:2024/05/18 00:30
题目链接:点击打开链接;
题意:求:3^0 + 3^1 +...+ 3^(N) mod 1000000007;
分析:快速幂,没啥说的
代码如下:
#include <set>#include <queue>#include <math.h>#include <vector>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <algorithm>using namespace std;const int mod=1000000007;long long quick_mod(long long a,long long b){ long long ans=1; while(b){ if(b&1){ ans=ans*a%mod; b--; } b>>=1; a=a*a%mod; } return ans;}int main(){ int n; scanf("%d",&n); n+=1; long long sum=(quick_mod(3,n)-1+mod)%mod; sum=(sum*500000004)%mod; printf("%I64d\n",sum);}
1 0
- 51nod 1031(快速幂)
- 51nod 1126(矩阵快速幂)
- 51nod 1004 【快速幂】
- 矩阵快速幂 51nod
- 51nod 1046 A^B Mod C (快速幂)
- 51nod 1046 A^B Mod C(快速幂)
- 51nod 1537 分解(矩阵快速幂)
- 51Nod 1118 机器人走方格(dp/快速幂)
- 51nod 1668 非010串(矩阵快速幂)
- 51nod 1033 骨牌覆盖 V2(矩阵快速幂)
- 51nod 1341 混合序列 (矩阵快速幂)
- 51nod 1113矩阵快速幂
- 51nod - 1573 分解 - 矩阵快速幂
- 51nod 1537 分解 (矩阵快速幂)
- 51nod-1113 矩阵快速幂
- 51nod 1013【快速幂+逆元】
- 51nod 1113 矩阵快速幂
- 51Nod 1113 矩阵快速幂
- 图片裁剪缩略处理小工具类
- 程序员能力提升
- 判断两个html元素是否重叠的函数
- 程序员要学会读源代码
- JS立即执行
- 51nod 1031(快速幂)
- Python 文件读写
- Jeff Atwood倾情推荐——程序员必读之书
- “UITableView完美平滑滚动”阅读笔记
- Matlab多线程与多核运算, 以及GPU加速
- Git学习8:Git分支操作
- 所有编程皆为Web编程
- 正则表示式实例1--判断某个数是不是4的幂数
- hiho 60. Permutation Sequence