#P5973. Decomposition of n into k Distinct Factors

    ID: 19198 Type: Default 1000ms 256MiB

Decomposition of n into k Distinct Factors

Decomposition of n into k Distinct Factors

Given two positive integers \( n \) and \( k \), determine whether it is possible to express \( n \) as a product of \( k \) distinct positive integers. If such a decomposition exists, output YES and one possible set of \( k \) distinct factors whose product equals \( n \). Otherwise, output NO.

The factors can be output in any order, but all must be distinct. Note that 1 is considered a positive integer and may be used at most once.

Explanation:

  • If \( k = 1 \), the only factor is \( n \) itself.
  • If \( k = 2 \) and \( n \gt 1 \), a valid solution is always \( 1 \) and \( n \) (since \( 1 \times n = n \)).
  • For \( k \ge 3 \), a greedy approach can be used: use k-2 proper divisors (all \( \ge 2 \) and chosen in increasing order to ensure distinctness) and then let the last factor be the remaining quotient. Finally, add 1 as a factor to complete the \( k \) factors. The decomposition is valid if all factors are distinct and their product equals \( n \).
  • Special care must be taken when \( n \) is prime or when it is not possible to find enough distinct divisors.

inputFormat

The input consists of a single line containing two integers \( n \) and \( k \) (with \( 1 \le n \le 10^9 \) and \( 1 \le k \le 20 \)), separated by a space.

outputFormat

If a valid decomposition exists, output YES in the first line, and in the second line output \( k \) distinct positive integers (separated by spaces) whose product equals \( n \). If no such decomposition exists, output NO.

sample

100 3
YES

1 2 50

</p>