372. Super Pow 发表于 2022-02-03 12345678910111213141516171819202122232425262728293031323334353637class Solution { private static final int BASE = 1337; public int superPow(int a, int[] b) { return superPow(a, b, b.length - 1); } private int superPow(int a, int[] b, int endIndex) { if (endIndex == -1) { // 注意此处是 -1, 0 是需要计算的 return 1; } int power = b[endIndex]; return quickPow(superPow(a, b, endIndex - 1), 10) * quickPow(a, b[endIndex]) % BASE; } private int quickPow(int a, int b) { if (b == 0) { return 1; } // 注意可能越界的地方都要进行求余 a %= BASE; int res = 1; while (b > 0) { if ((b & 1) == 1) { res = res * a % BASE; } a = a * a % BASE; b >>= 1; } return res; }} Reference372. Super Pow