372. Super Pow
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.
Example 1:
Input: a = 2, b = [3]
Output: 8Example 2:
Input: a = 2, b = [1,0]
Output: 1024Example 3:
Input: a = 1, b = [4,3,3,8,5,2]
Output: 1Example 4:
Input: a = 2147483647, b = [2,0,0]
Output: 1198Constraints:
1 <= a <= 231 - 11 <= b.length <= 20000 <= b[i] <= 9bdoesn't contain leading zeros.
# @lc code=start
using LeetCode
function super_pow(a::Int, b::Vector{Int})
md, ϕ = 1337, 1140
n = length(b)
n == 0 && return 1
e = 0
a %= md
for digit in b
e = (10 * e + digit) % ϕ
end
powermod(a, e, md)
end
# @lc code=endsuper_pow (generic function with 1 method)
This page was generated using DemoCards.jl and Literate.jl.