beecrowd | 3374

F of a and b to the k

By ACM International Collegiate Programming Contest, Kuwait University AE United Arab Emirates

Timelimit: 1

Consider the following function:


Given a pair of values <V,K>, write a program to determine if there are values for a, b, and k satisfying all of the following:

0 < a b < 10
0 ≤ kK
k (a,b) = V


Your program will be given a series of pairs <V ,K>, each pair on a separate line. Note that 0 ≤ V < 1,000, 000.

The end of the input file is identified by a dummy pair (which is not part of the test cases) where both V and K are 0.


For each given pair <V ,K>, if there are values for ab,and k satisfying the requirements, write on a separate line, the following output: 


If there is more than one solution, print the solution with the smallest value of k within all the solutions with the smallest value of b within all the solutions with the smallest value of a. (In other words, the first solution if they were sorted lexicographically in an ascending order using the key <a,b,k>.)

If there is no solution, print the following:

"no solution for <V,K>"

Input Sample Output Sample

5 10
5 1
34 3
34 4
34 20
0 0

no solution for <34,3>