• + 0 comments

    Python3 solution

    from math import gcd
    
    def primesTo(n):
        sieve = [True] * n
        for i in range(3, int(n ** 0.5) + 1, 2):
            if sieve[i]:
                sieve[i * i:: 2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
        return [2] + [i for i in range(3, n, 2) if sieve[i]]
    
    def solve(A):
        if A[0] == 1 or A[1] == 1:
            return 1
        m = min(A)
        primes = primesTo(m + 1)
        total = 1
        modo = 10 ** 9 + 7
        for p in primes:
            temp = p
            while temp <= m:
                total = (total * pow(p, (A[0] // temp) * (A[1] // temp), modo)) % modo
                temp *= p         
        return total % modo
    
    A = list(map(int, input().split()))
    print(solve(A))