Super Pow问题及解法
来源:互联网 发布:nginx location 正则 编辑:程序博客网 时间:2024/06/08 10:19
问题描述:
our 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 = 2b = [3]Result: 8
a = 2b = [1,0]Result: 1024
问题分析:
利用欧拉准则和递归的方法,即可求得答案。
这里简单说一下欧拉准则:ab % k = (a%k)(b%k)%k
过程详见代码:
class Solution {public: const int base = 1337;int powmod(int a, int k){a %= base;int res = 1;for (int i = 0; i < k; i++){res = (res * a) % base;}return res;}int superPow(int a, vector<int>& b) {if (b.empty()) return 1;int last = b.back();b.pop_back();return powmod(superPow(a, b), 10) * powmod(a, last) % base;}};
阅读全文
0 0
- Super Pow问题及解法
- Pow(x, n)问题及解法
- Super Ugly Number问题及解法
- Super Pow
- Super Pow
- Super Pow
- Super Pow
- Super Pow
- Pow(x, n) / Super Pow
- 【LeetCode】50. Pow(x, n)解法及注释
- Heaters问题及解法
- Permutations问题及解法
- Combinations问题及解法
- Subsets问题及解法
- Triangle问题及解法
- Minesweeper问题及解法
- leetcode.372. Super Pow
- LeetCode 372 Super Pow
- 【数据结构与算法】-常见排序算法总结
- 优秀程序员的修养与职业规划借鉴
- InputStream与OutputStream的比较
- android.content.res.Resources$NotFoundException:String resource ID #0x86
- 明确不站队BAT,帆软——这家只有几百人的BI公司靠什么赢得生存?
- Super Pow问题及解法
- 为什么你的用户总是不满意?
- 在Spring的XML文件中通过命名空间配置的标签是怎么解析的?
- spring mvc 报错 expected at least 1 bean which qualifies as autowire candidate for this depende (201
- 范数(L21,L2,核范数)
- asp.net(一)——c#基础
- 华为张延德:智慧城市是必然趋势 | 洞见2018中国HR服务峰会惊艳业界
- 入门到放弃node系列之网络模块(二)
- 盒子模型初学