题目
你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出。
示例 1:
输入:a = 2, b = [3]
输出:8
示例 2:
输入:a = 2, b = [1,0]
输出:1024
示例 3:
输入:a = 1, b = [4,3,3,8,5,2]
输出:1
示例 4:
输入:a = 2147483647, b = [2,0,0]
输出:1198
代码实现
class Solution {
static final int MOD = 1337;
public int superPow(int a, int[] b) {
int ans = 1;
for (int e : b) {
ans = (int) ((long) pow(ans, 10) * pow(a, e) % MOD);
}
return ans;
}
public int pow(int x, int n) {
int res = 1;
while (n != 0) {
if (n % 2 != 0) {
res = (int) ((long) res * x % MOD);
}
x = (int) ((long) x * x % MOD);
n /= 2;
}服务器托管网
服务器托管网 return res;
}
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
4CCE1MCP Design: Making a Connection Prepared by Dr Francesco CirielloYou will be required to undertake this alternative assessmen…