Sources of Power
All submissions for this problem are available.
While having the tea WonderKing and WonderMath was
talking about sources in the world natural sources like sun, rain. Then again petroleum sources. King was saying whole run on these sources, then the professor WonderMath said dear friend not only us humans, even numbers has their own magical sources, king was amazed and professor was
explaining more like following.
Every number has its own Magical Source. We represent Magical Source
by M and the number by P. M is a magical source of a number P, If the sum of a
sequence of n numbers where the ith number is m x 10i is equal to P.
Consider following examples.
S is regarded as a “ Lucky Set “ because they are going to be released for sure, an integer interval [ A, B ] where A is smaller than B, and A and B are positive integers is considered “ Unlucky “ if none of the integers between A and B, inclusive belongs to the Lucky Set. Largest unlucky interval containing prisoner numbered X will be imprisoned for whole life time. Your program
should find the largest unlucky interval containing the given integer X.
1234 x 100 = 1234
1234 x 101 = 12340
1234 x 102 = 123400
1234 x 103 = 1234000
1234 x 104 = 12340000
1234 + 12340 + 123400 + 1234000 + 12340000 = 13710974
So 1234 is a Magical Source of 13710974
Similar to above example,
99 + 990 + 9900 + 99000 = 109989
Magical Source of 108889 is 99.
Note by this definition, a positive number is a Magical Source of
itself. After such a long explanation WonderMath gave a challenge to his
friend WonderKing. I am giving you set of numbers you must have their
smallest magical source by tomorrow morning. King loved these kinds of
challenges, but this is a big task, will you help him to find
the smallest magical source of a given number and to win his challenge?
Input file, the first line is number of cases ( < 10) and then followed by
numbers P ( < 1010) that you need to find the Magical Source.
The Magical Source of each number.Constraints
- 100 <= N <= 999
- 100 <= N <= 999
3 13710974 109989 28416Sample Output:
1234 99 256
Explained in the above section.
|Time Limit:||0.2432 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.5, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.