Let's define A(n) for positive integer n as a sum of factorials of its digits. For example, A(154)=1!+ 5! +4!= 145.
Given a number 'x' , you need to print the minimum number L such that A(L)=x. If no such L exists, then print -1
First line contains 'T' - the number of test cases
Then each line contains an integer 'x'.
Print the answer for each value 'x'.
A(18)=1!+ 8! =40321 and 18 is the smallest element for which A(18) is 40321
Note that A(80) = A(81) is also 40321, But among them 18 is the smallest number.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.