372. Super Pow [Medium] 数学

2019-07-23  本文已影响0人  一个想当大佬的菜鸡
372. Super Pow
class Solution(object):
    def superPow(self, a, b):
        """
        :type a: int
        :type b: List[int]
        :rtype: int
        """
        b_num = 0
        for i in b:
            b_num = b_num * 10
            b_num += i
        return self.pow(a, b_num)
    def pow(self, a, b):
        res = 1
        base = a
        while b > 0:
            i = b & 1
            b = b >> 1
            if i:
                res = base * res % 1337
            base = base * base % 1337
        return res
上一篇 下一篇

猜你喜欢

热点阅读