The Devil Number
All submissions for this problem are available.
With the increasing popularity of Chef Po, many other chefs started to dislike him. So one day they decided that they will make chef Po indulge in a question so that he could not complete the food service in time, which will result in his unpopularity. They went to Chef Po and asked him, given a number N find the greatest Devil number K such that K<=N. A number is Devil if it contains only 1 and 3. But Chef Po is well aware of these cunning tricks of other chefs, so he called you, a programmer, for his help to find the required devil number.
First line of input contains a number T, the number of test cases. Each of the next T line contains a number N.
For each N, print its corresponding devil number in a new line.
Input: 2 41 18467
Output: 33 13333
|Time Limit:||0.114444 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.