/* -*- coding: utf-8 -*- * * 368.cc: No.368 LCM of K-products - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000; const int MAX_K = 1000; const int MAX_P = 31623; // >=sqrt(10^9) typedef long long ll; const ll MOD = 1000000007; /* typedef */ typedef vector vi; typedef pair pii; typedef vector vpii; typedef map mivi; /* global variables */ bool primes[MAX_P + 1]; int as[MAX_N]; /* subroutines */ void gen_primes(int maxp, vi &pnums) { memset(primes, true, sizeof(primes)); primes[0] = primes[1] = false; int p; for (p = 2; p * p <= maxp; p++) if (primes[p]) { pnums.push_back(p); for (int q = p * p; q <= maxp; q += p) primes[q] = false; } for (; p <= maxp; p++) if (primes[p]) pnums.push_back(p); } bool prime_decomp(int n, vi &pnums, vpii& pds) { pds.clear(); int pn = pnums.size(); for (int i = 0; i < pn; i++) { int pi = pnums[i]; if (pi * pi > n) { if (n > 1) pds.push_back(pii(n, 1)); return true; } if (n % pi == 0) { int fi = 0; while (n % pi == 0) n /= pi, fi++; pds.push_back(pii(pi, fi)); } } return false; } ll powmod(ll a, int b) { ll pm = 1; while (b > 0) { if ((b & 1) != 0) pm = (pm * a) % MOD; a = (a * a) % MOD; b >>= 1; } return pm; } /* main */ int main() { vi pnums; gen_primes(MAX_P, pnums); int n, k; cin >> n >> k; mivi pvs; for (int i = 0; i < n; i++) { int ai; cin >> ai; vpii pds; prime_decomp(ai, pnums, pds); for (vpii::iterator vit = pds.begin(); vit != pds.end(); vit++) pvs[vit->first].push_back(vit->second); } ll lcm = 1; for (mivi::iterator mit = pvs.begin(); mit != pvs.end(); mit++) { const int &pi = mit->first; vi &v = mit->second; sort(v.begin(), v.end(), greater()); //printf("%d:", pi); //for (int i = 0; i < v.size(); i++) printf(" %d", v[i]); putchar('\n'); int sum = 0, maxi = min(k, (int)v.size()); for (int i = 0; i < maxi; i++) sum += v[i]; lcm = (lcm * powmod((ll)pi, sum)) % MOD; } printf("%lld\n", lcm); return 0; }