[LeetCode]372. Super Pow
来源:互联网 发布:模拟人生4作弊码mac 编辑:程序博客网 时间:2024/05/16 14:21
https://leetcode.com/problems/super-pow/#/description
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.
a ^ 123456 % 1337 = (a ^ 123450 % 1337) * (a ^ 6 % 1337) % 1337 = ((a ^ 12345) ^ 10 % 1337) * (a ^ 6 % 1337) % 1337
mod(a, b, k) = (a ^ b) % k
public class Solution { public int superPow(int a, int[] b) { return superPow(a, b, b.length, 1337); } private int superPow(int a, int[] b, int n, int k) { if (n == 1) { return mod(a, b[0], k); } return mod(superPow(a, b, n - 1, k), 10, k) * mod(a, b[n - 1], k) % k; } private int mod(int a, int b, int k) { a %= k; int res = 1; for (int i = 0; i < b; i++) { res = res * a % k; } return res; }}
0 0
- leetcode.372. Super Pow
- LeetCode 372. Super Pow
- [LEETCODE] 372. super pow
- LeetCode--372. Super Pow
- leetcode 372. Super Pow
- Leetcode 372. Super Pow
- [leetcode] 372. Super Pow
- Leetcode: 372.Super Pow
- 372. Super Pow(LeetCode)
- LeetCode 372. Super Pow
- [LeetCode]372. Super Pow
- [leetcode]372. Super Pow
- leetcode 372. Super Pow
- LeetCode—372. Super Pow
- Leetcode 372. Super Pow[medium]
- [leetcode] 372. Super Pow 解题报告
- 【leetcode】372. Super Pow【M】【40】
- leetcode 336. Palindrome Pairs 372. Super Pow
- 1
- 多校联盟#con1 数学题
- 将Excel表格或者CSV文件导入到Mysql中
- spark sql 中出现的问题
- hibernate二级只读缓存设置 --oracle 是对sessionFactory而言的
- [LeetCode]372. Super Pow
- Codeforces #402 (Div. 2) C. Dishonest Sellers
- 输入n个整数,找出其中最小的K个数
- Python3 从HTTP代理网站批量获取代理并筛选
- RAFT 论文中文翻译(1)
- Linux centos7一键安装lamp
- Java 中的悲观锁和乐观锁的实现
- 【摘录】大数据挖掘与知识发现的应用领域
- mac 安装使用Liteide