#P2674. Polygonal Number Identification
Polygonal Number Identification
Polygonal Number Identification
This is a pattern search problem designed to exercise your mathematical induction skills. A number is called a polygonal number if it can be represented in the form of a polygon. More formally, for an integer K ≥ 3, the K-gonal number with index n is given by the formula:
$$P(K,n)=\frac{(K-2)n(n-1)}{2}+n.$$
For example, when K=3 the formula represents triangular numbers and when K=4 it represents square numbers. Note that for any K, the first polygonal number is always 1 (i.e. when n=1).
Task: Given an integer N, determine if it is a K-gonal number for some K ≥ 3 (with n > 1) and, if so, output the two smallest such values of K (in increasing order) if there is more than one possibility. If there is exactly one possibility, output that single K. If N is not a polygonal number (for any K with a valid n > 1), then output the string "Poor" concatenated with N (i.e. "PoorN").
Note: For the special case when N=1, since 1 is the first polygonal number for any K, output the two smallest values: 3 and 4.
inputFormat
The input begins with an integer T representing the number of test cases. Each of the following T lines contains a single integer N.
Constraints: It is guaranteed that the input data allow the solution to run in reasonable time.
outputFormat
For each test case, output the result in one line:
- If N is a polygonal number for one or more values of K, output the smallest one if there is exactly one. If there are at least two, output the two smallest values (separated by a space).
- If N is not a polygonal number (with n > 1), output the string "PoorN" (i.e. the word Poor concatenated with N without a space).
sample
4
1
36
5
22
3 4
3 4
5
5 22
</p>