#Ti-Basic (TI-84 Plus CE), 48 41 bytes
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)