INUMBER - Interesting number

For the given number n find the minimal positive integer divisable by n, with the sum of digits equal to n.

Input

t – the number of test cases, then t test cases follow. (t <= 50)
Test case description:
n - integer such that 0 < n <= 1000

Output

For each test case output the required number (without leading zeros).

Example

Input:
2
1
10

Output:
1
190

Added by:Roman Sol
Date:2005-01-13
Time limit:7s
Source limit:4096B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:XII team championship of St.-Petersburg in programming

hide comments
2015-02-19 08:49:57 VISHAL DEEPAK AWATHARE
once you find a way to generate the results we can well do /

Last edit: 2015-02-19 08:51:11
2014-07-18 13:09:56 Archit Jain
enjoyed solving this
2014-04-21 16:35:22 IKKA
how to get accepted using STL
2014-03-31 17:19:23 yousef hadder
got AC But with 6.50S,, any suggestions for a faster algorithm ??
2014-01-05 19:07:12 Kamil
What kind of trick do we need to pass memory limit?
2012-12-27 09:00:32 Shafaet
@kshitij agrawal: I've used STL and got ac.
2011-12-19 11:42:43 kshitij agrawal
Difficult one ..... Don't use STL...

P.S: I am 279th user to do this 279th problem .. :)

Last edit: 2011-12-19 12:25:55
2010-10-20 14:35:11 Hy Trường Sơn
i think so

Last edit: 2010-10-20 14:35:45
2009-07-31 08:40:40 .:: Pratik ::.
You don't need big int...
2009-07-12 21:00:43 Drew Saltarelli
input : 1000
output : 1999999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999999999999999999
999000

which is a 118 digit number. You will need bignums or a
language that can support arbitrary big numbers (i.e. python)


Last edit: 2009-07-12 22:09:21
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.