class Solution(object):
    def fast_power(self, a, b, n):
        if n == 1:
            return a%b
        if n == 0:
            return 1%b
        p = self.fast_power(a, b, n//2)
        p = (p*p)%b
        if n%2 == 1:
            p = (p*a)%b
        return p

s = Solution()
print(s.fast_power(3, 7, 5))

35d2e8f1eabe8473475f107acd8c8afd733252d4
class Solution(object):
    <mask token>


<mask token>

class Solution(object):

    def fast_power(self, a, b, n):
        if n == 1:
            return a % b
        if n == 0:
            return 1 % b
        p = self.fast_power(a, b, n // 2)
        p = p * p % b
        if n % 2 == 1:
            p = p * a % b
        return p


<mask token>

class Solution(object):

    def fast_power(self, a, b, n):
        if n == 1:
            return a % b
        if n == 0:
            return 1 % b
        p = self.fast_power(a, b, n // 2)
        p = p * p % b
        if n % 2 == 1:
            p = p * a % b
        return p


<mask token>
print(s.fast_power(3, 7, 5))

class Solution(object):

    def fast_power(self, a, b, n):
        if n == 1:
            return a % b
        if n == 0:
            return 1 % b
        p = self.fast_power(a, b, n // 2)
        p = p * p % b
        if n % 2 == 1:
            p = p * a % b
        return p


s = Solution()
print(s.fast_power(3, 7, 5))

class Solution(object):
    def fast_power(self, a, b, n):
        if n == 1:
            return a%b
        if n == 0:
            return 1%b
        p = self.fast_power(a, b, n//2)
        p = (p*p)%b
        if n%2 == 1:
            p = (p*a)%b
        return p

s = Solution()
print(s.fast_power(3, 7, 5))
