관리 메뉴

솜씨좋은장씨

[leetCode] 372. Super Pow (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 372. Super Pow (Python)

솜씨좋은장씨 2020. 7. 15. 19:12
728x90
반응형

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: 8

Example 2:

Input: a = 2, b = [1,0]
Output: 1024

Solution

class Solution:
    def superPow(self, a: int, b: List[int]) -> int:
        answer = 1
        for b_val in b[::-1]:
            answer = answer * a ** b_val % 1337
            a = pow(a, 10) % 1337
        return answer

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments