372 Super Pow 超级次方
生活随笔
收集整理的這篇文章主要介紹了
372 Super Pow 超级次方
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
你的任務是計算 ab 對 1337 取模,a 是一個正整數,b 是一個非常大的正整數且會以數組形式給出。
示例 1:
a = 2
b = [3]
結果: 8
示例 2:
a = 2
b = [1,0]
結果: 1024
詳見:https://leetcode.com/problems/super-pow/description/
C++:
class Solution { public:int superPow(int a, vector<int>& b) {long long res = 1;for (int i = 0; i < b.size(); ++i){res = pow(res, 10) * pow(a, b[i]) % 1337;}return res;}int pow(int x, int n) {if (n == 0){return 1;}if (n == 1){return x % 1337;}return pow(x % 1337, n / 2) * pow(x % 1337, n - n / 2) % 1337;} };?參考:https://www.cnblogs.com/grandyang/p/5651982.html
轉載于:https://www.cnblogs.com/xidian2014/p/8848125.html
總結
以上是生活随笔為你收集整理的372 Super Pow 超级次方的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle 跨库查询表数据(不同的数据
- 下一篇: Madgwick算法详细解读