#include #include #include #include #include #include #include #include #include #include #include #define _fetch(_1, _2, _3, _4, name, ...) name #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c)) #define rep(...) _fetch(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__) #define getchar getchar_unlocked #define putchar putchar_unlocked using namespace std; using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u8 = unsigned char; using f80 = long double; using f64 = double; using u128 = __uint128_t; template struct Mod { Mod() : n_(0) {} Mod(word n) : n_(init(n)) {} static void init_mod(word m) { mod = m, inv = -mul_inv(m), r2 = dword(-m) * (-m) % m; } static word mul_inv(word n) { word x = n; rep(_, 5) x *= 2 - n * x; return x; } static word reduce(dword w) { word x = word(w) * inv; word y = (dword(x) * mod + w) >> (8 * sizeof(word)); return (y >= mod) ? y - mod : y; } static word init(word n) { return reduce(dword(n) * r2); } static word ilog2(word n) { return (n == 0) ? 0 : (63 - __builtin_clzll(n)); } Mod& operator += (Mod rhs) { if ((n_ += rhs.n_) >= mod) n_ -= mod; return *this; } Mod& operator -= (Mod rhs) { if ((n_ += mod - rhs.n_) >= mod) n_ -= mod; return *this; } Mod& operator *= (Mod rhs) { n_ = reduce(dword(n_) * rhs.n_); return *this; } bool operator == (Mod rhs) { return n_ == rhs.n_; } bool operator != (Mod rhs) { return !(*this == rhs); } Mod operator + (Mod rhs) { return Mod(*this) += rhs; } Mod operator - (Mod rhs) { return Mod(*this) -= rhs; } Mod operator * (Mod rhs) { return Mod(*this) *= rhs; } Mod operator - () { return (n_ == 0) ? *this : Mod() - *this; }; Mod pow(word e) { if (e == 0) return Mod(1); Mod ret = Mod(*this); for (word mask = (word(1) << ilog2(e)) >> 1; mask > 0; mask >>= 1) { ret *= ret; if (e & mask) ret *= *this; } return ret; } word val() { return reduce(n_); } friend ostream& operator << (ostream& os, Mod& m) { return os << m.val(); } word n_; static word mod, inv, r2; }; using word = u32; using dword = u64; using mint = Mod; template <> word mint::mod = 0; template <> word mint::inv = 0; template <> word mint::r2 = 0; template class Factor { private: struct ExactDiv { ExactDiv() {} ExactDiv(fint n) : n(n), i(mint::mul_inv(n)), t(fint(-1) / n) {} friend fint operator / (fint n, ExactDiv d) { return n * d.i; }; bool divide(fint n) { return n / *this <= this->t; } fint n, i, t; }; vector primes; public: Factor(u32 n) { init(n); } void init(u32 n) { u32 sqrt_n = sqrt(n); vector isprime(n + 1, 1); rep(i, 2, sqrt_n + 1) if (isprime[i]) rep(j, i * i, n + 1, i) isprime[j] = 0; primes.clear(); rep(i, 2, n + 1) if (isprime[i]) primes.push_back(ExactDiv(i)); } fint brent(fint n, fint c) { // n must be composite and odd. mint::init_mod(n); const fint s = 256; const mint one = mint(1); auto f = [&](mint x) { return x * x + c; }; mint y = one; for (fint l = 1; ; l <<= 1) { auto x = y; rep(_, l) y = f(y); mint p = one; rep(k, 0, l, s) { rep(_, min(s, l - k)) y = f(y), p *= y - x; fint g = gcd(n, p.n_); if (g == 1) continue; if (g == n) for (g = 1; g == 1; ) y = f(y), g = gcd(n, (y - x).n_); return g; } } } bool miller_rabin(fint n) { if (!(n & 1)) return n == 2; if (n <= 8) return true; mint::init_mod(n); fint d = n - 1; fint s = __builtin_ctzll(d); d >>= s; mint one = mint(1); auto composite = [&](mint b) { b = b.pow(d); if (b == one || b == -one) return false; rep(_, s - 1) { b *= b; if (b == -one) return false; } return true; }; fint bases[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; rep(i, 7) { mint b = mint(bases[i] % n); if (b == 0) return true; if (composite(b)) return false; } return true; } using P = pair; vector

factors(fint n) { assert(n < (fint(-1) >> 1)); auto ret = vector

(); if (!(n & 1)) { u32 e = ctz(n); ret.emplace_back(2, e); n >>= e; } fint lim = square(primes[primes.size()-1].n); rep(pi, 1, primes.size()) { auto p = primes[pi]; if (square(p.n) > n) break; if (p.divide(n)) { u32 e = 1; n = n / p; while (p.divide(n)) n = n / p, e++; ret.emplace_back(p.n, e); } } u32 s = ret.size(); while (n > lim && !miller_rabin(n)) { for (fint c = 1; ; ++c) { fint p = brent(n, c); if (!miller_rabin(p)) continue; u32 e = 1; n /= p; while (n % p == 0) { n /= p; e += 1; } ret.emplace_back(p, e); break; } } if (n > 1) ret.emplace_back(n, 1); if (ret.size() - s >= 2) sort(ret.begin() + s, ret.end()); return ret; } private: fint gcd(fint a, fint b) { while (b) { fint t = a % b; a = b; b = t; } return a; } fint ctz(fint n) { return __builtin_ctzll(n); } fint square(fint n) { return n * n; } }; void solve() { auto f = Factor(1000); const u32 MOD = 1e9 + 7; u32 n, k; while (~scanf("%u %u", &n, &k)) { map > cnts; rep(i, n) { u32 a; scanf("%u", &a); for (auto& p : f.factors(a)) cnts[p.first].push_back(p.second); } u32 ans = 1; for (auto& pp : cnts) { auto p = pp.first; auto& v = pp.second; sort(v.begin(), v.end()); u32 e = 0; rep(i, min(u32(v.size()), k)) { e += v[v.size() - 1 - i]; } rep(i, e) ans = u64(ans) * p % MOD; } printf("%u\n", ans); } } int main() { // clock_t beg = clock(); solve(); // clock_t end = clock(); // fprintf(stderr, "%.3f sec.\n", double(end - beg) / CLOCKS_PER_SEC); return 0; }