Awesome Numbers
Time limit0.5sMemory limit512 MB
Decide whether n is reachable from 1 by repeatedly applying P (nth prime) or S (nth perfect square), and print the shortest such sequence.
- Level
Hard9 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
As everyone knows, Kipa's favorite integer is 120. It has the following properties.
- .
- It is the first triperfect number.
- It is the factorial of 5.
- It is the 10th highly composite number.
- It is the 15th triangular number.
The properties are listed in Kipa's order of preference.
Kipa also likes integer families, meaning subsets of the integers that satisfy some property. Kipa likes two families that are not on the list above: the primes and the perfect squares. So Kipa defined these operations:
- : the th prime.
- : the th perfect square.
For example, applies three times to 1, and applies , then , then . Kipa starts from 1 and repeatedly applies or . The integers reachable this way form the awesome numbers. Given a positive integer, decide whether it is an awesome number and make Kipa happy.
Input
The first line contains the number of test cases . is a positive integer at most .
Each of the next lines contains a positive integer at most .
Output
Print lines, similar to the sample output. For those who complained about the word "similar", the conditions are written below as regular expressions.
- If is not an awesome number, print
-1. - If is an awesome number, print the shortest string that satisfies all of the following conditions.
- The regular expression
^1( [PS] [1-9][0-9]*)*$accepts . - The regular expression
^.*n\$accepts . - For any substring that has a non-digit character immediately before and after :
- If the regular expression
^([0-9]+) P ([0-9]+)\$accepts , thenP({1}) ={2}` holds. - If the regular expression
^([0-9]+) S ([0-9]+)\$accepts , thenS({1}) ={2}` holds.
- If the regular expression
- The regular expression
If is an awesome number, at least one string satisfying these conditions is guaranteed to exist. If several shortest exist, you may print any one of them.