lintcode ----快速幂
来源:互联网 发布:数据筛选删除数据 编辑:程序博客网 时间:2024/06/05 07:15
a^n % b
1.如果n 为奇数可以转化为 (a^(n/2) * a^(n/2) * a ) %b = ((a^(n/2)%b * a^(n/2)%b)%b * a%b) %b
2. 如果n 为偶数可以转化为 (a^(n/2) * a^(n/2) ) %b = (a^(n/2)%b * a^(n/2)%b)%b
int fastPower(int a, int b, int n) { // write your code here if(n==0) return 1%b; else if(n==1) return a%b; else { long long tem = fastPower(a,b,n/2); if(n&1) return ((tem*tem)%b)*a%b; else return (tem*tem%b); } }
0 0
- LintCode-快速幂
- Lintcode快速幂
- lintcode-快速幂-125
- LintCode 快速幂
- Lintcode 快速幂
- lintcode之快速幂
- lintcode ----快速幂
- LintCode 140-快速幂
- LintCode :快速幂
- lintcode(140)快速幂
- 快速幂-LintCode
- [LintCode]140.快速幂
- 快速幂—LintCode
- [LintCode] 快速幂 Fast Power
- LintCode-剑指Offer-(140)快速幂
- lintcode刷题——快速幂
- LintCode
- lintcode--
- Two Sum III - Data structure design
- httpClient
- C++ split 分割字符串
- PayPal支付集成到自己Web网站
- 请不要这样告诉孩子
- lintcode ----快速幂
- HDU3653->数位DP
- 政治的架构
- 修改 EditText 中的光标位置
- Leetcode 27. Remove Element (Easy) (cpp)
- 需要解决post提交数据的时候,乱码的问题:在web.xml里做配置:
- mysql 将数据导出成excel文件(.xls格式)
- 排列组合和回溯算法-面试题
- Inno Setup脚本语法大全