All submissions for this problem are available.
Little John Von Neumann has just been introduced to the world of numbers by his father. He has been fiddling around with them for some time now and already makes much more sense of them than a seasoned professional. (Note: He's just 6 years old)
In particular, he is fascinated by the fact that how just 9 digits can form countless numbers. In his terminology, a number m is child of a parent number n if
- they have the same non-zero digits (their order may be different),
- the number of zero digits in the child are less than or equal to the number of zero digits in his parent and
- m is less than n.
For example numbers 120, 102, 12, etc are children of 1200.
(Note: Leading zeros are not allowed in m)
Little Von Neumann is interested in finding the number of children of a number. Could you amuse him?
First line contains, 1<= t<=50, the number of test cases, and then t lines follows,
Each line has one number n;
- n will not start with a '0'.
- n will have between 1 and 50 characters, inclusive.
- n will consists of only digits between ('0', '9').
- There will be at most 2^63 - 1 children with the same non-zero digits as n that are less than n
For each test case output total number of children possible.
Input: 4 9177 1020 50000000000000 1030000040000 Output: 9 7 13 1414 Explanation: For test case 1 Children of 9177 are: 7179, 7719, 7791, 7971, 7197, 1779, 1797, 1797 and 1977.
|Time Limit:||0.198 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, GO, NODEJS|
Fetching successful submissions
If you are still having problems, see a sample solution here.