import math def primes2(limit): ''' returns a list of prime numbers upto limit. source: Rossetta code: Sieve of Eratosthenes http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Odds-only_version_of_the_array_sieve_above ''' if limit < 2: return [] if limit < 3: return [2] lmtbf = (limit - 3) // 2 buf = [True] * (lmtbf + 1) for i in range((int(limit ** 0.5) - 3) // 2 + 1): if buf[i]: p = i + i + 3 s = p * (i + 1) + i buf[s::p] = [False] * ((lmtbf - s) // p + 1) return [2] + [i + i + 3 for i, v in enumerate(buf) if v] def read_data(): N, K = map(int, input().split()) As = list(map(int, input().split())) return N, K, As def solve(N, K, As): mod = 10**9 + 7 max_a = max(As) primes = primes2(int(max_a**0.5)) ans = 1 for p in primes: counts = [0] * int(math.log(max_a, p) + 2) for i, a in enumerate(As[:]): c = 0 while (not a % p): a //= p c += 1 As[i] = a counts[c] += 1 pows = 0 k = K for i in range(len(counts) - 1, -1, -1): ci = counts[i] if k <= ci: pows += i * k break pows += i * ci k -= ci ans = (ans * pow(p, pows, mod)) % mod As.sort() prev_a = 1 count = 0 for a in As: if a != prev_a: ans = (ans * a) % mod count = 1 prev_a = a elif count < K: ans = (ans * a) % mod count += 1 return ans N, K, As = read_data() print(solve(N, K, As))