#include #include #include using namespace std; typedef map Number; typedef long long ll; const ll kMOD = 1000 * 1000 * 1000 + 7; const int kMAX_N = 1010; const int kMAX_K = 1010; int N, K; set dp[kMAX_N][kMAX_K]; int a[kMAX_N]; Number PrimeFactor(int n) { Number res; for (int i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) res[n] = 1; return res; } void Solve() { Number n; n[1] = 1; dp[0][0].insert(n); for (int i = 0; i < N; i++) { for (int j = 0; j <= K; j++) { if (dp[i][j].empty()) continue; for (set::iterator it = dp[i][j].begin(); it != dp[i][j].end(); it++) { Number new_num = *it, a_factors = PrimeFactor(a[i]); // かけないで使う dp[i + 1][j].insert(*it); if (j + 1 > K) continue; // かけて使う for (Number::iterator n_it = a_factors.begin(); n_it != a_factors.end(); n_it++) { new_num[n_it->first] += n_it->second; } dp[i + 1][j + 1].insert(new_num); } } } Number result; for (set::iterator it = dp[N][K].begin(); it != dp[N][K].end(); it++) { Number num = *it; for (Number::iterator n_it = num.begin(); n_it != num.end(); n_it++) { result[n_it->first] = max(result[n_it->first], n_it->second); } } ll answer = 1; for (Number::iterator n_it = result.begin(); n_it != result.end(); n_it++) { for (int i = 0; i < n_it->second; i++) { answer *= n_it->first; answer %= kMOD; } } cout << answer << endl; } int main() { cin >> N >> K; for (int i = 0; i < N; i++) { cin >> a[i]; } Solve(); return 0; }