Files
PAT/html/a1103.html
T

37 lines
1.8 KiB
HTML

<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h1>1103. Integer Factorization (30)</h1>
<div id="problemContent">
<p>The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K-P factorization of N for any positive integers N, K and P.</p>
<p><b>
Input Specification:
</b></p>
<p>Each input file contains one test case which gives in a line the three positive integers N (&lt;=400), K (&lt;=N) and P (1&lt;P&lt;=7). The numbers in a line are separated by a space.</p>
<p><b>
Output Specification:
</b></p>
<p>For each case, if the solution exists, output in the format:</p>
<p>
N = n<sub>1</sub>^P + ... n<sub>K</sub>^P
</p>
<p>
where <b>n<sub>i</sub></b> (i=1, ... K) is the i-th factor. All the factors must be printed in non-increasing order.</p>
<p>
Note: the solution may not be unique. For example, the 5-2 factorization of 169 has 9 solutions, such as 12<sup>2</sup> + 4<sup>2</sup> + 2<sup>2</sup> + 2<sup>2</sup> + 1<sup>2</sup>, or 11<sup>2</sup> + 6<sup>2</sup> + 2<sup>2</sup> + 2<sup>2</sup> + 2<sup>2</sup>, or more. You must output the one with the maximum sum of the factors. If there is a tie, the largest factor sequence must be chosen -- sequence { a<sub>1</sub>, a<sub>2</sub>, ... a<sub>K</sub> } is said to be <b>larger</b> than { b<sub>1</sub>, b<sub>2</sub>, ... b<sub>K</sub> } if there exists 1&lt;=L&lt;=K such that a<sub>i</sub>=b<sub>i</sub> for i&lt;L and a<sub>L</sub>&gt;b<sub>L</sub>
</p>
<p>
If there is no solution, simple output "Impossible".
</p>
<b>Sample Input 1:</b><pre>
169 5 2
</pre>
<b>Sample Output 1:</b><pre>
169 = 6^2 + 6^2 + 6^2 + 6^2 + 5^2
</pre>
<b>Sample Input 2:</b><pre>
169 167 3
</pre>
<b>Sample Output 2:</b><pre>
Impossible
</pre>
</div>