All submissions for this problem are available.
Dash’s Palindromic Milestones
One of Mr. Incredible’s greatest opponents , Cixelsyd, was dyslexic. When reading a word or a number (especially an isolated one), he would get confused and would sometimes read from right to left instead of left to right. When he was building the Grand National highway to unite his vast empire, he decided to number the milestone in such a manner that he would never get confused while travelling. His ingenious solutions was to leave all milestone blank , except those carrying the number that read same both forwards and backwards. So, the first 10 milestones would be 0,1,2,……..9 ( where 0 is the starting point) followed by 101,111,121, etc. Milestone for the distances that are not of this form are left blank.
Dash is running along one such highway starting from the capital, and to keep himself alert, decides to play the following game. When dash is at distance k miles from the capital, he picks up the number n and tries to guess what will be the number on the ‘n’th non-blank milestone from this point (not including the current milestone , if there is any). Design a program to do this.
The input will contain several test cases.
The first line contains a positive integer N having the number of number of test cases.
For every test case, there are 2 lines.
The first line contains the positive integer k ( the miles covered so far) and the second line contains n ( which milestones value is to be calculated).
Input Constraints: n and k must be between 1 and 10000
Your output should be one line per test case , giving the reading on the n-th non blank milestones after the k-th mile.
Input: 2 13 2 99 3 Output: 33 121
Input: 1 100000 100000 Output: 910999019
|Time Limit:||0.181818 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.