Super Pow
来源:互联网 发布:围棋 人工智能算法 编辑:程序博客网 时间:2024/04/30 22:10
Super Pow
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
Example1:
a = 2b = [3]Result: 8
Example2:
a = 2b = [1,0]Result: 1024解析:
每一位一位的的求,当前位为之前所有位的结果的10次方再乘以a的当前位次方。
代码:
class Solution {public: int spow(int a,int b) { int base=1337; a%=1337; int res=1; for (int i=0; i<b; i++) { res*=a; res%=base; } return res; } int superPow(int a, vector<int>& b) { int ans=1; int base=1337; for (int i=0; i<b.size(); i++) { ans=(spow(ans,10)*spow(a,b[i]))%base; } return ans; }};
0 0
- Super Pow
- Super Pow
- Super Pow
- Super Pow
- Super Pow
- Pow(x, n) / Super Pow
- leetcode.372. Super Pow
- LeetCode 372 Super Pow
- leetcode372. Super Pow
- LeetCode 372. Super Pow
- 372. Super Pow
- LeetCode Super Pow详解
- 372. Super Pow
- [LEETCODE] 372. super pow
- leetcode Super Pow
- LeetCode--372. Super Pow
- 372. Super Pow
- LeetCode: Super Pow
- 销售员业绩管理程序设计
- linux 取文本的指定行的内容
- MySql 5.7 zip 安装
- 常用排序算法之快速排序
- Java概念性问题3
- Super Pow
- 关于web项目的乱码问题总结
- vim 高亮行号配置
- Javascript写简易计算器
- ACdream 1060 递推数
- mybatis+mysql如何批量执行多条语句
- myeclipse中表单提交乱码问题
- WPF应用
- iOS面试笔记(1)