Calculating the maximum product of a subsequence with prime factorization

TypeScript Hard math

Task «Calculating the maximum product of a subsequence with prime factorization»

Given a sequence of integers a1, a2, ..., an. It is necessary to find the maximum product of a subsequence (not necessarily contiguous) of length k, where k is given. It is allowed to divide elements into their prime factors, but no more than once per element. That is, for each element you can either take it entirely, or replace it with one of its prime factors (if it is not a prime number), and only then use it in the product. If an element is a prime number, you can only take it entirely or not take it. It is required to output the maximum possible product modulo 10^9+7.

Input Format

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 1000). The second line contains n integers a_i (2 ≤ a_i ≤ 10^9).

Output Format

Output a single integer — the maximum product modulo 10^9+7.

main.ts