#K9746. Three Numbers Puzzle
Three Numbers Puzzle
Three Numbers Puzzle
You are given two positive integers \(S\) and \(P\), where \(S\) is the sum of three distinct positive integers \(a\), \(b\) and \(c\) (with \(a < b < c\)), and \(P\) is their product. Your task is to determine the three numbers.
It is known that the three numbers satisfy the following conditions:
- There exist at least two different triples \((a, b, c)\) that sum to \(S\). (In this case, one might say "I cannot determine the three numbers." )
- There exist multiple triples \((a, b, c)\) that produce the product \(P\). (That is, even knowing \(P\), one cannot uniquely determine the triple.)
- After further discussion based on these observations, it becomes possible to uniquely identify the triple \((a, b, c)\).
You are given \(S\) and \(P\) for a test case that satisfies the above conditions. If there is a triple \((a, b, c)\) that meets \(a+b=S\) and \(a\times b\times c=P\), output the triple in increasing order (i.e. \(a\ b\ c\)). If no such triple exists, output -1.
inputFormat
The input consists of two integers \(S\) and \(P\) separated by space or newline, where:
- \(S\) is the sum of the three numbers, i.e. \(a + b + c\).
- \(P\) is the product of the three numbers, i.e. \(a \times b \times c\).
You may assume that \(1 \leq a < b < c \leq 1000\) (if a valid triple exists).
outputFormat
If there is a valid triple of numbers that satisfy the conditions, output the three numbers in increasing order separated by a space. Otherwise, output -1.
## sample6 6
1 2 3