Python solution


  • 0
    C
    # 60 m
    def superPow(self, a, b):
        m = 1337
        a %= m
        # [Euler's totient theorem]
        #   a^phi(m) = 1 mod m
        # We can calculate phi(a) offline.
        # 1377 = 7 * 191
        # phi(1377) = phi(7) * phi(191)
        #           = 6 * 190
        #           = 1140
        phi = 1140 
        if not b:
            return 1
        e = 0
        for d in b:
            e = (e*10 + d) % phi
        return pow(a, e, m)
    
    

  • 0
    R

    It is very impressed,but It is wrong.Sorry.
    Please see this topic.Thanks!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.