[Question]
  [
Given a positive integer, find its smallest positive integer multiple which is a run of 9 followed by an optional run of 0. In other words, find its smallest positive integer multiple which is matched by the regex `/^9+0*$/`.
For example, if the given positive integer is 2, then return 90, since 90 is a positive integer multiple of 2 and is the smallest which is matched by the regex `/^9+0*$/`.
Test cases:
```
n  f(n)
1  9
2  90
3  9
4  900
5  90
6  90
7  999999
8  9000
9  9
10 90
11 99
12 900
13 999999
14 9999990
15 90
16 90000
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest answer in bytes wins. [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~13~~ 11 bytes
```
ṚḌ‘DS=ḍ@ð1#
```
[Try it online!](https://tio.run/##ATEAzv9qZWxsef//4bma4biM4oCYRFM94biNQMOwMSP/MTJS4bifNzsxNcK1OyLDh@KCrEf/ "Jelly – Try It Online")
### How it works
```
ṚḌ‘DS=ḍ@ð1#  Main link. Argument: n
        ð    Start a dyadic chain with arguments n and n.
         1#  Execute the chain to the left with left argument k = n, n+1, n+2, ...
             and right argument n until 1 match has been found. Return the match.
Ṛ                Get the decimal digits of k, reversed.
 Ḍ               Convert from base 10 to integer.
                 This essentially removes trailing zeroes. As a side effect, it
                 reverses the digits, which doesn't matter to us.
  ‘              Increment the resulting integer. If and only if it consisted
                 entirely of 9's, the result is a power of 10.
   DS            Compute the sum of the digits. The sum is 1 if and only if the
                 integer is a power of 10. Note that the sum cannot be 0.
      ḍ@         Test k for divisibility by n.
     =           Compare the results.
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~55~~ 54 bytes
```
n=r=input()
while int(`10*r`.lstrip('9')):r+=n
print r
```
[Try it online!](https://tio.run/##JYy9DoIwGEVn7lN0K2hi@PhTSDri6uIDoKQJDaQ0nyXK09cal7Pcc4/b/bTaIrwns2hx5013SDzvkYn@6FFIKYNVrIx1m08z/EVjfTpQfuDhtLw8G5fKVmZZx0dl4TjOgkO8IkZG7bzob9eeeeVf98n6MQdCgRIVajQ444IWlIMIVIBKUAWqQc0X "Python 2 – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 51 bytes
```
f=lambda n,r=9:r%n and f(n,10*r-10**n*r%-n/n*9)or r
```
[Try it online!](https://tio.run/##FcyxDoIwFAXQWb/iLi/Qpo0tGyT4LyVYJdELeYGBr69lOePZzv2zsislj9/0m@YEOh37QYVInJFbuhis@oqlVfF80PZmVWjJVWIhNPH9aqNDDMEM99umC3c00h3wT8jRQFCjazOm/AE "Python 2 – Try It Online")
[Answer]
# JavaScript (ES6), ~~47~~ ~~43~~ 42 bytes
*-4 bytes thanks to @Arnauld*  
*-1 byte thanks to @Luke*
```
n=>eval('for(i=0;!/^9+0*$/.test(i);)i+=n')
```
## Tests
```
let f=
n=>eval('for(i=0;!/^9+0*$/.test(i);)i+=n')
for(let i=1;i<=16;i++)console.log(`f(${i}) = `+f(i))
```
### Recursive solution (fails for 7, 13, and 14), 38 bytes
```
n=>g=(i=0)=>/^9+0*$/.test(i+=n)?i:g(i)
```
Called like `f(5)()`. Reaches the max call stack size in Chrome and Firefox for `n=7`, `n=13`, and `n=14`.
```
f=
n=>g=(i=0)=>/^9+0*$/.test(i+=n)?i:g(i)
for(let i=1;i<=16;i++){
	try { console.log(`f(${i}) = `+f(i)()) }
	catch(e) { console.log(`f(${i}) = FAILED`) }
}
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 36 bytes
```
->x{r=0;1until"#{r+=x}"=~/^9+0*$/;r}
```
Brute-forcing - takes forever for x=17.
[Try it online!](https://tio.run/##KypNqvyfZvtf166iusjWwNqwNK8kM0dJubpI27aiVsm2Tj/OUttAS0Xfuqj2v6FeaUFJvoahmWZ1TUVNQWlJsYKSaoqCaoqSanSFTlp0RWxs7X8A "Ruby – Try It Online")
[Answer]
# Java 8, ~~61~~ 57 bytes
```
n->{int r=0;for(;!(""+r).matches("9+0*");r+=n);return r;}
```
-4 bytes (and faster execution) thanks to *@JollyJoker*.
**Explanation:**
[Try it here.](https://tio.run/##LY7BbsIwDIbvPIXXU7KIqj1NU@jeAC4cpx1CCBDWupXjIiHUZy8ORXIs5Y/95bu6m1v3Q8Dr8X/2rUsJti7iYwUQkQOdnA@wy9dXAF7ljtpKMsmRSuw4etgBQgMzrn8eeYSayp56UvZDFYUhXXaO/SUkVXyb6rPQlkwjGAo8EgLZabYLbhgPreDe1Fsfj9CJkdozRTz//oHTi06m559iU1uIm/pLujHvR4D9PXHoyn7kcpBNblFhKfr65b7YT6tpfgI)
```
n->{                              // Method with integer as parameter and return-type
  int r=0;                        //  Result-integer
  for(;!(""+r).matches("9+0*");   //  Loop as long as `r` doesn't match the regex
    r+=n                          //   And increase `r` by the input every iteration
  );                              //  End of loop
  return r;                       //  Return the result-integer
}                                 // End of method
```
[Answer]
# [Python 3](https://docs.python.org/3/), 56 bytes
```
f=lambda n,r=0:{*str(r).strip('0')}!={'9'}and n+f(n,n+r)
```
[Try it online!](https://tio.run/##VYvBCoJAFEXX@RWvlTM2hNIiklxEEAyVi3LTSkzHGsg38mZaRPjtJraIVpdzuKd9ubvBRV@TaYCUNU8qFeimNeQg8EZtX/ZnPKscPXSjHTsd5FFm@TnbbPcCRsxlupOpzC4C/pDzsVPlk6w2@O0jWK9hEfK@Th5Fc60KQEFJGL8D64gRnw@jW@aHPu@mydtf@V2BFeCsZihwRkNoCBA0AhV4UywSEC157E1a0ujYcOO8/wA "Python 3 – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 16 bytes
```
;I×≜.ẹḅhᵐc~a₀90∧
```
[Try it online!](https://tio.run/##AS8A0P9icmFjaHlsb2cy//87ScOX4omcLuG6ueG4hWjhtZBjfmHigoA5MOKIp///MTL/Wg "Brachylog – Try It Online")
This is pretty slow
### Explanation
```
;I×≜.              Output = Input × I
    .ẹḅ            Deconcatenate into runs of consecutive equal digits
       hᵐ          Take the head of each run
         c         Concatenate into a number
          ~a₀90∧   That number is a prefix of 90 (i.e. it's 9 or 90)
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 10 bytes
```
0[+D9Û0«_#
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fIFrbxfLwbINDq@OV//@3BAA "05AB1E – Try It Online")
It just keeps adding the input to 0, until the result minus leading 9's equals 0.
[Answer]
# [RProgN 2](https://github.com/TehFlaminTaco/RProgN-2), 18 bytes
```
x={x*'^9+0*$'E}éx*
```
## Explained
```
x={x*'^9+0*$'E}éx*
x=                  # Set the value of "x" to the input.
  {           }é    # Find the first positive integer in which passing it to the defined function returns truthy.
   x*               # Multiply the index by x, this essentially searches multiples now.
     '^9+0*$'       # A Regex defined by a literal string.
             E      # Does the multiple match the regex?
                x*  # Multiple the outputted index by x, giving the result.
```
[Try it online!](https://tio.run/##Kyooyk/P0zX6/7/CtrpCSz3OUttAS0Xdtfbwygqt////mwIA "RProgN 2 – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 38 + 1 = 39 bytes
Uses `-p` flag.
```
$_=y=eval$_
1until"#{$_+=y}"=~/^9+0*$/
```
`-p` surrounds the program with:
```
while gets
    ...
end
puts $_
```
`gets` stores its result in `$_`. `eval` is used to convert it to a number, as it's shorter than `.to_i`, then brute force is used, incrementing $\_ until it matches the regex. `"#{}"` is sttring interpolation, it's shorter than a `.to_s` call as that would require parantheses around `$_+=y`. Finally, `$_` is printed.
[Try it online!](https://tio.run/##KypNqvz/XyXettI2tSwxRyWey7A0ryQzR0m5WiVe27ayVsm2Tj/OUttAS0X//3@Tf/kFJZn5ecX/dQsA "Ruby – Try It Online\"ine")
[Try all test cases!](https://tio.run/##BcFLCoMwFAXQ@V1F0TeqFL3@WgfZiqGCA0Gi1EQIRZfu85xfGKKqWBPNuH9nsWBwfpqT9C82M/FIzJn3XVY8Jdc1@O0hVokSFWo0aPHGBx1YgARLsAJrsAHba1n9tLhNX@4G)
[Answer]
# [Mathics](http://mathics.github.io/), 71 bytes
```
(x=#;While[!StringMatchQ[ToString@x,RegularExpression@"9+0*"],x+=#];x)&
```
[Try it online!](https://tio.run/##y00sychMLv6fZvtfo8JW2To8IzMnNVoxuKQoMy/dN7EkOSMwOiQfwnWo0AlKTS/NSSxyrSgoSi0uzszPc1Cy1DbQUorVqdC2VY61rtBU@x8AVFvikOZg8h8A "Mathics – Try It Online")
Not very intresting brute force solution, but it beats the other Mathematica answer, which uses some clever tricks.
The one redeeming quality Mathematica has in regards to this challenge is the fact that `StringMatchQ` requires a full match, so I can do `9+0*` rather than `^9+0*$`.
[Answer]
## Batch, 175 bytes
```
@set/pn=
@set s=
:g
@set/ag=-~!(n%%2)*(!(n%%5)*4+1)
@if not %g%==1 set s=0%s%&set/an/=g&goto g
@set r=1
:r
@set s=9%s%
@set/ar=r*10%%n
@if %r% gtr 1 goto r
@echo %s%
```
Takes input on STDIN. Not a brute force solution but in fact based on my answer to [Fraction to exact decimal](https://codegolf.stackexchange.com/questions/89215) so it will work for 17, 19, etc. which would otherwise exceed its integer limit anyway.
[Answer]
# Mathematica, 127 bytes
```
Select[FromDigits/@Select[Tuples[{0,9},c=#],Count[#,9]==1||Union@Differences@Flatten@Position[#,9]=={1}&],IntegerQ[#/c]&][[1]]&
```
  
**Input**
> 
> [17]
> 
> 
> 
**Output**
> 
> 9999999999999999
> 
> 
> 
***here are the first 20 terms***
> 
> {9, 90, 9, 900, 90, 90, 999999, 9000, 9, 90, 99, 900, 999999,
>  9999990, 90, 90000, 9999999999999999, 90, 999999999999999999, 900}
> 
> 
> 
[Answer]
# [Haskell](https://www.haskell.org/), 53 bytes
`f` takes and returns an integer.
```
f n=filter(all(<'1').snd.span(>'8').show)[n,n+n..]!!0
```
[Try it online!](https://tio.run/##FcvdCoJAEIbhW/mEwJVicPzLILuR6GDIFZfWUVzDy9/s8IXnHSV8rPdxEqed082u8t5OX/VObaBJFhPGeaeBVit9Rvu89iEO0G5w/sBGvDf3lNOMgvYUFlHzSNt/Hlv21IueleiVJHmMjAIlKtRocEWLGzgHM7gAl@AKXIObHw "Haskell – Try It Online")
This times out for 17, which conveniently is just beyond the test cases. A faster version in 56 bytes:
```
f n=[x|a<-[1..],b<-[0..a-1],x<-[10^a-10^b],mod x n<1]!!0
```
[Try it online!](https://tio.run/##FchLCoMwFAXQrVyhgxb0kedf0JVIhFgjSjUpxqKD7j21s8OZlHvpZfGrmk0zm11v6rnfPmaZjXa0qvfdTfagkTathgcddhucH2Ga9vyqOmqZSIb9BUGkIpbh@U/RXRZdL8PVDjhhapZBILxnxEiQIkOOAiUqsAAzOAYn4BScgXNwAS7BFWLxAw "Haskell – Try It Online")
# How it works
* `f` generates all multiples of `n`, converts each to a string, filters out those with the right format, then takes the first one.
* The faster version instead uses that the required numbers are of the form `10^a-10^b`, `a>=1`, `a>b>=0`. For golfing purposes it also uses the fact that for the minimal `a`, only *one* `b` can work, which allows it to generate the `b`s in the slightly shorter "wrong" order.
[Answer]
# [Perl 5](https://www.perl.org/), 23 + 2 (-pa) = 25 bytes
**Brute Force Method**
```
$_+=$F[0]while!/^9+0*$/
```
[Try it online!](https://tio.run/##K0gtyjH9/18lXttWxS3aILY8IzMnVVE/zlLbQEtF//9/o3/5BSWZ@XnF/3V9TfUMDA3@6xYkAgA "Perl 5 – Try It Online")
It's slow, but it's tiny.
## More Efficient Method:
41 + 2 (-pa) = 43 bytes
```
$_=9;s/0/9/||($_=9 .y/9/0/r)while$_%$F[0]
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3tbSuljfQN9Sv6ZGA8RT0KsEcgz0izTLMzJzUlXiVVXcog1i//83NPmXX1CSmZ9X/F/X11TPwNDgv25BIgA "Perl 5 – Try It Online")
It works well for any input, but it's longer code.
[Answer]
# Dyalog APL, 34 bytes
```
{∧/'0'=('^9+'⎕R'')⊢⍕⍵:⍵⋄∇⍵+r}n←r←⎕
```
Recursive dfns, based on [Dennis' Python solution](https://codegolf.stackexchange.com/a/130113/65326).
[Answer]
**C++, 106 bytes**
```
int main(){long N,T=9,j=10,M;cin>>N;while(T%N){if(T/j){T+=(M/j);j*=10;}else{T=(T+1)*9;j=10;M=T;}}cout<<T;}
```
Detailed Form:
```
int main()
{
    long N,T=9,j=10,M;
    cin >> N;
    while (T%N)
    {
        if (T/j)
        {
            T += (M/j);
            j *= 10;
        }
        else
        {
            T = (T+1)*9;
            j = 10;
            M = T;
        }
    } 
    cout << T;
}
```
[TRY it online!](https://tio.run/##RYtLDoMgFEXnroKkaQLVfkxH5gk70BEbIEj1GUBTMB0Y107pqLOTe@7R63odtU4n9NpugyEtLiG@jXKi@G9Oxek2iWIL6EfilTNhVdqQEAdI6CNxCj1lu12y7ivJm2rm9aPqQKMXoofPhNZQee7Zji8q7zPbZclplwHmS77CYWwwu@RUljW7NPDroeMSjkMvW2zbTCnVzy8)
[Answer]
# [Python 2](https://docs.python.org/2/), 79 bytes
```
x=input();n=10;y=9
while y%x:
 b=n
 while(b-1)*(y%x):b/=10;y=n-b
 n*=10
print y
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v8I2M6@gtERD0zrP1tDAutLWkqs8IzMnVaFStcKKSyHJNo9LASygkaRrqKmlARTWtErSh6jN003iUsjTAnK4Cooy80oUKv//NzQFAA "Python 2 – Try It Online")
**Some explanations**
It finds the smallest natural of form `10**n-10**b` with `n>b>=0` that divides the input.
**Some IO**
```
f(1) = 9
f(2) = 90
f(3) = 9
f(4) = 900
f(5) = 90
f(6) = 90
f(7) = 999999
f(8) = 9000
f(9) = 9
f(10) = 90
f(11) = 99
f(12) = 900
f(13) = 999999
f(14) = 9999990
f(15) = 90
f(16) = 90000
f(17) = 9999999999999999
f(18) = 90
f(19) = 999999999999999999
```
[Answer]
# [PHP](https://php.net/), 39 bytes
```
for(;ltrim($r=$argn*++$i,9)>0;);echo$r;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRwJVaVJRfFF@UWpBfVJKZl65R5xrv5x/i6eyqac2lkliUnmerZGiiZP0/Lb9IwzqnpCgzV0OlyBYso6WtrZKpY6lpZ2CtaZ2anJGvUmT9/z8A "PHP – Try It Online")
# [PHP](https://php.net/), 52 bytes
```
for(;!preg_match("#^9+0*$#",$r=$argn*++$i););echo$r;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRwJVaVJRfFF@UWpBfVJKZl65R5xrv5x/i6eyqac2lkliUnmerZGiiZP0/Lb9Iw1qxoCg1PT43sSQ5Q0NJOc5S20BLRVlJR6XIFqxUS1tbJVPTWtM6NTkjX6XI@v9/AA "PHP – Try It Online")
[Answer]
## Swift 3.0, Bytes:121
```
var i=2,m=1,n=""
while(i>0){n=String(i*m)
if let r=n.range(of:"^9+0*$",options:.regularExpression){print(n)
break};m=m+1}
```
[Try it online!](https://iswift.org/playground)
[Answer]
# [Python 3](https://docs.python.org/3/), 62 bytes
This function takes an integer `n` and initializes `m` to zero. Then it removes all zeros from the ends of `m` and checks if the result only contains 9's, returning `m` if it does. If not, it adds `n` to `m` and checks again, etc.
```
def f(n,m=0):
 while{*str(m).strip('0')}!={'9'}:m+=n
 return m
```
[Try it online!](https://tio.run/##FcxBCoMwEEDRvaeYrjJTQ1G6KBVyGKGJBswYphEj4tnT9G/@7sUjzSs/S/lYBw5ZB9PR0MA@@8We928SDPSo8xFVp@i6mVO91TWE1nADYtMmDKG4VSCDZ5CRJ4u9hv71d2pRPCfMuvKZqPwA "Python 3 – Try It Online")
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 66 bytes, doesn't choke on 17
```
n->{long a=10,b=1;for(;(a-b)%n>0;b=(b<10?a*=10:b)/10);return a-b;}
```
[Try it online!](https://tio.run/##LU/BbsIwDL3zFe8yKYG1tOy2UPYF48Jx2sEpAYUVp0pTpAn124tLkWxLtp@f37vQjbLQOr4c/8a6oa7DN3m@LwDPycUT1Q77qQWawGfUSuZgbWQ0SEp0iZKvsQejwsjZ7v5EUlUW77YqzSlEZRRlVr/xrjC2UnZbFl@0FMCn1euy0Ca61EeGgMwwmpm37W0jvC/6W/BHXEWbOqTo@fzzC9KzsOnBpMrLM/jt5kPqavVaAof/LrlrHvqUt3KZGlaciw/9NDHbGBbD@AA "Java (OpenJDK 8) – Try It Online")
Longer than @KevinCruijssen's [solution](https://codegolf.stackexchange.com/a/130105/58251) but can handle slightly larger numbers. It calculates the candidate numbers like 10^6 - 10^3 = 999000. 64-bit longs are still the limit, breaking for n=23.
Can probably be golfed a bit but already took too long to make it work...
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 35 bytes
```
&a:v ;n-<
:,a/?(1:^!?%&:&-}:{
a*:\~
```
[Try it online](https://tio.run/##S8sszvj/Xy3RqkzBOk/XhstKJ1HfXsPQKk7RXlXNSk231qqaK1HLKqbu////umUKRpYA "><> – Try It Online"), or watch it at the [fish playground](https://fishlanguage.com/playground)!
Assumes the input is already on the stack. Works by looking for numbers of the form 10a − 10b, with a < b (yes, that's a less than sign — it takes fewer bytes!) until that's divisible by the input, then printing 10b − 10a. This is much faster than the brute force method (which would be difficult in ><> anyway).
[Answer]
# [V](https://github.com/DJMcMayhem/V), ~~19~~ 14 bytes
```
é0òÀ/[1-8]ü09
```
[Try it online!](https://tio.run/##K/v///BKg8ObDjcw6kcb6lrEHt5jYPn//39LAA "V – Try It Online")
## Explanation
```
é0              ' &ltm-i>nsert a 0
  ò             ' &ltm-r>ecursively
   À            ' &ltm-@>rgument times
               ' &ltC-A> increment the number (eventually gives all multiples)
     /[1-8]ü09  ' find ([1-8]|09) if this errors, the number is of the form
                ' (9+0*) (because there won't ever be just zeros)
                ' implicitly end the recursion which breaks on the above error
```
[Answer]
## JavaScript (ES6), ~~51~~ 49 bytes
```
let
f=(n,x=1,y=1)=>(x-y)%n?f(n,x,y*10):x-y||f(n,x*10)
```
```
<input type=number value=1 step=1 min=1 oninput=O.value=f(value)>
<input type=number value=9 id=O disabled>
```
Not the shortest approach, but it is wicked fast.
[Answer]
## Mathematica, 82 bytes
Using the pattern of submission from [@Jenny\_mathy 's answer](https://codegolf.stackexchange.com/a/130112/42612)...
```
(d=x=1;y=0;f:=(10^x-1)10^y;n:=If[y>0,y--;x++,y=d;d++;x=1];While[Mod[f,#]!=0,n];f)&
```
Input:
```
[17]
```
Output:
```
9999999999999999
```
And relative to the argument in comments at @Jenny\_mathy's answer with [@Phoenix](https://codegolf.stackexchange.com/users/60042/phoenix) ... `RepeatedTiming[]` of application to the input `[17]` gives
```
{0.000518, 9999999999999999}
```
so half a millisecond. Going to a slightly larger input, `[2003]` : 
```
{3.78, 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999}
```
a bit under 4 seconds.
Test table: On the first 30 positive integers, the results are 
```
{9, 90, 9, 900, 90, 90, 999999, 9000, 9, 90, 99, 900, 999999, 
9999990, 90, 90000, 9999999999999999, 90, 999999999999999999, 900, 
999999, 990, 9999999999999999999999, 9000, 900, 9999990, 999, 
99999900, 9999999999999999999999999999, 90}
```
Explanation:
The only magic here is the custom iterator ("iterator" in the CS sense, not the M'ma sense)
```
n := If[ y>0  ,  y-- ; x++  ,  y=d ; d++ ; x=1]
```
which acts on the global variables `x`, the number of leading "9"s, `y`, the number of trailing "0"s, and `d`, the total number of digits. We wish to iterate through the number of digits, and, for each choice of number of digits, start with the most "0"s and the least "9"s. Thus the first thing the code does is initialize `d` to 1, forcing `x` to 1 and `y` to 0. The custom iterator checks that the string of "0"s can be shortened. If so, it shortens the string of "0"s by one and increases the string of "1"s by one. If not, it increments the number of digits, sets the number of "0"s to one less than the number of digits, and sets the number of "9"s to 1. (This is actually done in a slightly different order to shave a few characters, since the old value of `d` is the desired value of `y`.)
[Answer]
# Ti-Basic (TI-84 Plus CE), ~~48~~ 41 bytes
```
Prompt X
For(K,1,0
For(M,-K+1,0
10^(K)-10^(-M
If 0=remainder(Ans,X
Return
End
End
```
Input is `Prompt`-ed during the program; output is stored in `Ans`.
Explanation:
Tries numbers of the form (10n)(10m-1) = 10k-10m, where m+n=k starts at 1 and increases, and for each value of k, it tries m=1,n=k-1; m=2,n=k-2; ... m=k,n=0; until it finds a multiple of `X`.
This works up to 16; 17 gives a domain error because `remainder(` can only accept dividends up to 9999999999999 (13 nines), and 17 should output 9999999999999999 (16 nines).
```
Prompt X               # 3 bytes, input number
For(K,1,0              # 7 bytes, k in the description above; until a match is found
For(M,-K+1,0           # 10 bytes, start with n=1, m=(k-n)=k-1;
                           # then n=2, m=(k-n)=k-2, up to n=k, m=(k-n)=0
                           # (M=-m because it saved one byte)
10^(K)-10^(-M           # 8 bytes, n=(k-m) nines followed by m zeroes → Ans
If not(remainder(Ans,X # 8 bytes, If X is a factor of Ans (remainder = 0)
Return                 # 2 bytes, End program, with Ans still there
End                    # 2 bytes,
End                    # 1 byte (no newline)
```
[Answer]
# [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 53 bytes
```
{p=p+1┘o=p*9_F!o$|┘n=!A!~(_l!n$|=_l!n+1$|)-(o%:)|\_Xo
```
## Explanation
```
{        infinitely DO
p=p+1    raise p (starts out as 0)
┘o=p*9   Get the mext multiple of 9 off of p
_F!o$|   Flip a string representation of p*9
┘n=!A!   and set 'n' to be an int version of the flipped p*9 
         (this effectively drops trailing 0's)
~        This IF will subtract two values: the first is either 0 for n=x^10, or -1
         and the second bit does (p*9) modulo 'a' (input number): also 0 for the numbers we want
(
 _l!n$|  the length of n's string representation
=        is equal to
_l!n+1$| the length of (n+1)'s string rep (81 + 1 = 82, both are 2 long; 99 + 1 = 100, there's a difference)
)        The above yields -1 (Qbasic's TRUE value) for non-9 runs, 0 for n=x^10
-        Subtract from that 
(o%:)    (p*9) modulo a     0 for p*9 = a*y
|       THEN (do nothing, since we want 0+0=0 in the conditionals above, execution of the right path jumps to ELSE
\_Xo    ELSE quit, printing (p*9)
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 126 bytes
```
#include<stdio.h>
main(x,n,y,b){n=10;y=9;scanf("%d",&x);while(y%x){b=n;while((b-1)*(y%x)){b/=10;y=n-b;}n*=10;}printf("%d",y);}
```
[Try it online!](https://tio.run/##LYxLDsIgFAD3HqOmBhpQWbgwiHeBRz8k@GqkppCGq4u/LmeSGeA9QClbh@Cftr2EybpxP1w3N@2QRIYsMUMXVOIokzrLABo7UtW2YrtI5Tw435JUR7oYhSsSwwVtfvajD/8UuZEZmy/k@8PhtF4SlbkUcXpB53UfCp/f "C (gcc) – Try It Online")
**Some explanations**
It finds the smallest natural of form `10**n-10**b` with `n>b>=0` that divides the input.
**Some IO**
```
f(1) = 9
f(2) = 90
f(3) = 9
f(4) = 900
f(5) = 90
f(6) = 90
f(7) = 999999
f(8) = 9000
f(9) = 9
f(10) = 90
f(11) = 99
f(12) = 900
f(13) = 999999
f(14) = 9999990
f(15) = 90
f(16) = 90000
```
]