[Question]
  [
Given a positive integer `N`, output the smallest positive integer such that this number is a palindrome (i.e. is its own reverse) and is divisible by `N`.
The palindrome (i.e. the output) must not need a leading zero to be a palindrome, e.g. `080` is not the valid answer for `16`.
The input will never be a multiple of 10, because of the previous reason.
Your program may take as much time as necessary, even if in practice it would be way too long to output the answer.
### Inputs and outputs
* You may take the input through `STDIN`, as a function argument, or anything similar.
* You may print the output to `STDOUT`, return it from a function, or anything similar.
* Inputs and outputs must be in the decimal base.
### Test cases
```
N        Output
1        1
2        2
16       272
17       272
42       252
111      111
302      87278
1234     28382
```
### Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins.
  
[Answer]
# Haskell, ~~45~~ ~~37~~ 34 bytes
```
(+)>>=until((reverse>>=(==)).show)
```
[Answer]
# Pyth, 7 bytes
```
*f_I`*Q
```
Try it online: [Demonstration](https://pyth.herokuapp.com/?code=%2Af_I%60%2AQ&input=1234&debug=0)
### Explanation
```
*f_I`*QT)Q   implicit endings, Q=input number
 f      )    find the first number T >= 1, which satisfies:
     *QT        product of Q and T
    `           as string
  _I            is invariant under inversion (=palindrom)
*        Q   multiply this number with Q and print
```
[Answer]
# [2sable](https://github.com/Adriandmen/2sable) / [05AB1E](https://github.com/Adriandmen/05AB1E/), 6 / 7 bytes
**2sable**
```
[DÂQ#+
```
**Explanation**
```
[         # infinite loop
 D        # duplicate current number
  Â       # bifurcate
   Q#     # if the number is equal to its reverse, break loop
     +    # add input
          # implicitly print
```
[Try it online](http://2sable.tryitonline.net/#code=W0TDglEjKw&input=MzAy)
**05AB1E**
```
[DÂQ#¹+
```
The difference to the 2sable code is that input is only implicit once in 05AB1E, so here we need `¹` to get the first input again.
[Try it online](http://05ab1e.tryitonline.net/#code=W0TDglEjwrkr&input=MzAy)
Saved 1 byte with 2sable as suggested by [Adnan](https://codegolf.stackexchange.com/users/34388/adnan)
[Answer]
# **Java, ~~164~~ ~~159~~ ~~126~~ ~~108~~ 94 bytes**
Golfed version:
```
int c(int a){int x=a;while(!(x+"").equals(new StringBuffer(x+"").reverse()+""))x+=a;return x;}
```
Ungolfed version:
```
int c(int a)
{
    int x = a;
    while (!(x + "").equals(new StringBuffer(x + "").reverse() + ""))
        x += a;
    return x;
}
```
Shoutout to Emigna and Kevin Cruijssen for contributing improvements and cutting the bytes almost in half :)
[Answer]
**C#, 103 80 Bytes**
```
int f(int p){int x=p;while(x+""!=string.Concat((x+"").Reverse()))x+=p;return x;}
```
**Ungolfed**
```
int f(int p)
{
   int x = p;
   while (x + "" != string.Concat((x + "").Reverse()))
      x += p;
   return x;
}
```
[Answer]
# Python 2, 46 bytes
```
f=lambda x,c=0:`c`[::-1]==`c`and c or f(x,c+x)
```
[Ideone it!](http://ideone.com/x8gWMH)
Recursive solution with `c` as counter.
The case for `0` is interesting, because although `c=0` satisfies the palindrome condition, it would not be returned, because `ccc and 0 or xxx` always returns `xxx`.
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), 8 bytes
```
:L#>*.r=
```
[Try it online!](http://brachylog.tryitonline.net/#code=OkwjPioucj0&input=MTIzNA&args=Wg) (around 5 seconds for `1234`)
[Verify all testcases.](http://brachylog.tryitonline.net/#code=OjFhCjpMIz4qLnI9&input=WzE6MjoxNjoxNzo0MjoxMTE6MzAyOjEyMzRd&args=Wg&debug=on) (around 20 seconds)
```
:L#>*.r=
?:L#>*.r=.   Implicitly filling Input and Output:
             Input is prepended to every predicate,
             Output is appended to every predicate.
?:L  *.      Input*L is Output,
  L#>        L is positive,
      .r .   Output reversed is Output,
        =.   Assign a value to Output.
```
[Answer]
# PHP, 39 bytes
```
while(strrev($i+=$argv[1])!=$i);echo$i;
```
* Takes number N as argument $argv[1];
* `;` after while to do nothing
* `strrev` return string backward
Same length with for-loop
```
for(;strrev($i+=$argv[1])!=$i;);echo$i;
```
[Answer]
# Javascript (ES6), ~~55~~ 51 bytes
**4 bytes thanks to Neil.**
```
f=(x,c=x)=>c==[...c+""].reverse().join``?c:f(x,x+c)
```
```
<input type=number min=1 oninput=o.textContent=this.value%10&&f(+this.value)><pre id=o>
```
[Answer]
## Pyke, ~~11~~ 9 bytes
```
.f*`D_q)*
```
[Try it here!](http://pyke.catbus.co.uk/?code=.f%2a%60D_q%29%2a&input=16)
[Answer]
# C, ~~217~~ 189 bytes
Standalone version :
```
int a(char*b){int c=strlen(b);for(int i=0;i<c/2;i++)if(b[i]!=b[c-i-1])return 0;}int main(int e,char **f){int b,c;char d[9];b=atoi(f[1]);c=b;while(1){sprintf(d,"%d",c);if(a(d)&&(c/b)*b==c)return printf("%d",c);c++;}}
```
Call to a function version :
```
int s(char*a){int b=strlen(a);for(int i=0;i<b/2;i++)if(a[i]!=a[b-i-1])return 0;}int f(int a){int b;char c[9];b=a;while(1){sprintf(c,"%d",b);if(s(c)&&(b/a)*a==b)return printf("%d",b);b++;}}
```
Ungolfed :
```
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int check_palindrome(char *str) {
  int length = strlen(str);
  for (int i = 0; i < length / 2; i++) {
    if (str[i] != str[length - i - 1])
      return 0;
  }
  return 1;
}
int main(int argc, char **argv) {
  int number;
  int pal;
  char string[15];
  number = atoi(argv[1]);
  pal = number;
  while (1) {
    sprintf(string, "%d", pal);
    if (check_palindrome(string) && (pal / number) * number == pal)
      {
        printf("%d\n", pal);
        return 1;
      }
    pal++;
  }
  return 0;
}
```
Call to a function ungolfed :
```
int s(char *a) {
  int b = strlen(a);
  for (int i = 0; i < b / 2; i++) {
    if (a[i] != a[b - i - 1])
      return 0;
  }
  return 1; //We can remove it, it leads to a undefined behaviour but it works
}
int f(int a) {
  int b;
  char c[9];
  b = a;
  while (1) {
    sprintf(c, "%d", b);
    if (s(c) && (b / a) * a == b)
      {
        printf("%d\n", b); //no need for the \n
        return 1; //just return whatever printf returns, who cares anyway ?
      }
    b++;
  }
  return 0; //no need for that
}
```
I included the standalone version for historicity.
This is my first codegolf, any comment is welcome !
[Answer]
# R, ~~117~~ ~~113~~ ~~109~~ 101 bytes
```
D=charToRaw;P=paste;S=strtoi;a=P(i<-scan()+1);while(!all(D(a)==rev(D(a))&&S(a)%%i==0)){a=P(S(a)+1)};a
```
**Ungolfed**
```
i<-scan()        #Takes the input
D=charToRaw      #Some aliases
P=paste
S=strtoi
a=P(i+1)         #Initializes the output
while(!(all(D(a)==rev(D(a)))&&(S(a)%%i==0))) #While the output isn't a palindrom and isn't
                                             #divisible by the output...
    a=P(S(a)+1)
a
```
`all(charToRaw(a)==rev(charToRaw(a)))` checks if at each position of `a` the value of `a` and its reverse are the same (i.e., if `a` is palindromic).  
It might be possible to golf out some bytes by messing around with the `types`.
[Answer]
# [Actually](http://github.com/Mego/Seriously), ~~15~~ 14 bytes
Asked to answer by Leaky Nun. Golfing suggestions welcome. [Try it online!](http://actually.tryitonline.net/#code=4pWWMmDilZwqJDtSPWDilZNO4pWcKg&input=MTIzNA)
```
╖2`╜*$;R=`╓N╜*
```
**Ungolfing**
```
          Implicit input n.
╖         Save n in register 0.
2`...`╓   Push first 2 values where f(x) is truthy, starting with f(0).
  ╜*$       Push register 0, multiply by x, and str().
  ;R        Duplicate str(n*x) and reverse.
  =         Check if str(n*x) == reverse(str(n*x)).
          The map will always result in [0, the x we want].
N         Grab the last (second) value of the resulting list.
╜*        Push n and multiply x by n again.
          Implicit return.
```
[Answer]
# Haskell, ~~64 63~~ 56 bytes
```
x!n|mod x n==0,s<-show x,reverse s==s=x|y<-x+1=y!n
(1!)
```
Call with `(1!)16` or simply `1!16`. [Try it on Ideone.](http://ideone.com/qG7FUd)
[Answer]
**VBSCRIPT, 47 bytes**
```
do:i=i+1:a=n*i:loop until a=eval(strreverse(a))
```
**ungolfed**
```
do                     #starts the loop
i=i+1                  #increments i, we do it first to start at 1 instead of 0
a=                     #a is the output
n*i                    #multiply our input n by i
loop until 
a=eval(strreverse(a))  #end the loop when our output is equal to its reverse
```
[Answer]
# Perl, 25 bytes
Includes +2 for `-ap`
Run with the input on STDIN:
```
palidiv.pl <<< 16
```
`palidiv.pl`:
```
#!/usr/bin/perl -ap
$_+="@F"while$_-reverse
```
[Answer]
# [S.I.L.O.S](http://github.com/rjhunjhunwala/S.I.L.O.S), 109 bytes
```
readIO 
n = 0
lbla
n + i
a = n
r = 0
lblb
m = a
m % 10
r * 10
r + m
a / 10
if a b
r - n
r |
if r a
printInt n
```
[Try it online!](http://silos.tryitonline.net/#code=cmVhZElPIApuID0gMApsYmxhCm4gKyBpCmEgPSBuCnIgPSAwCmxibGIKbSA9IGEKbSAlIDEwCnIgKiAxMApyICsgbQphIC8gMTAKaWYgYSBiCnIgLSBuCnIgfAppZiByIGEKcHJpbnRJbnQgbg&input=&args=MzAy)
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 14 bytes
```
V±U s w ¥V?V:ß
```
[Try it online!](https://tio.run/nexus/japt#@x92aGOoQrFCucKhpWH2YVaH5///b2hkbAIA "Japt – TIO Nexus")
Thank you ETHproductions for the help! :)
[Answer]
# [MATL](http://github.com/lmendo/MATL), 10 bytes
```
0`G+tVtP<a
```
[Try it online!](http://matl.tryitonline.net/#code=MGBHK3RWdFA8YQ&input=MTIzNA)
```
0      % Push 0
`      % Do...while
  G+   %   Add the input. This generates the next multiple of the input
  tV   %   Duplicate, convert to string
  tP   %   Duplicate, reverse
  <a   %   Is any digit lower than the one in the reverse string? This is the
       %   loop condition: if true, the loop proceeds with the next iteration
       % End do...while
       % Implicitly display
```
[Answer]
## PowerShell v2+, 72 bytes
```
for($i=$n=$args[0];;$i+=$n){if($i-eq-join"$i"["$i".Length..0]){$i;exit}}
```
Long because of how reversing is handled in PowerShell -- not very well. ;-)
Takes input `$args[0]`, stores into `$i` (our loop variable) and `$n` (our input). Loops infinitely, incrementing `$i` by `$n` each time (to guarantee divisibility).
Each iteration, we check whether `$i` is a palindrome. There's some trickery happening here, so let me explain. We first take `$i` and stringify it with `"$i"`. That's then array-indexed in reverse order `["$i".length..0]` before being `-join`ed back into a string. That's fed into the right-hand side of the `-eq`uality operator, which implicitly casts the string back into an `[int]`, since that's the left-hand operand. Note: this casting does strip any leading zeros from the palindrome, but since we're guaranteed the input isn't divisible by `10`, that's OK.
Then, `if` it is a palindrome, we simply place `$i` onto the pipeline and `exit`. Output is implicit at the end of execution.
### Test Cases
```
PS C:\Tools\Scripts\golfing> 1,2,16,17,42,111,302,1234|%{"$_ -> "+(.\smallest-palindrome-divisible-by-input.ps1 $_)}
1 -> 1
2 -> 2
16 -> 272
17 -> 272
42 -> 252
111 -> 111
302 -> 87278
1234 -> 28382
```
[Answer]
# MATLAB, 76 bytes
```
function s=p(n)
f=1;s='01';while(any(s~=fliplr(s))) s=num2str(n*f);f=f+1;end
```
Call format is `p(302)` result is a string.
Nothing clever here. It does a linear search, using the `num2str()` and `fliplr()` functions.
This ugly arrangement is a touch shorter than using a `while(1) ... if ... break end` pattern.
Ungolfed
```
function s = findFirstPalindromeFactor(n)
  f = 1;                        % factor
  s = '01';                     % non-palindromic string for first try
  while( all(s ~= fliplr(s)) )  % test s not palindrome
    s = num2str( n * f );       % factor of input as string
    f = f + 1;                  % next factor
  end
 
```
[Answer]
## Mathematica, 49 bytes
```
(c=#;Not[PalindromeQ@c&&c~Mod~#==0]~While~c++;c)&
```
Starts the search at `c = N`, and increments `c` if not a palindrome and not divisible by `N`. When conditions are met, outputs `c`.
[Answer]
# Jelly, 12 bytes
```
¹µ+³ßµDU⁼Dµ?
```
[Try it online!](http://jelly.tryitonline.net/#code=wrnCtSvCs8OfwrVEVeKBvETCtT8&input=&args=MTY)
Explanation:
This link takes 1 argument. The `µ`s split it into 4 parts. Starting from the last and moving left:
```
           ? The three parts in front of this are the if, else, and
             condition of a ternary expression.
      DU⁼D  This condition takes a number n as an argument. It converts
            n to an array of decimal digits, reverses that array, and
            then compares the reversed array to the decimalization of
            n (ie is n palindromic in decimal?)
  +³ß  This is the else. It adds the original input argument to n
       and then repeats the link with the new value of n.
¹  This is the if. It returns the value passed to it.
```
[Answer]
# [Elixir](http://elixir-lang.org), 75 bytes
```
def f(p,a\\0),do: if'#{a+p}'|>Enum.reverse=='#{a+p}',do: a+p,else: f(p,a+p)
```
[Answer]
## Python 2, 66 65 bytes
`i` is input and `x` is (eventually) output
```
def f(i,x):
    y=x if x%i==0&&`x`==`x`[::-1]else f(i,x+1)
    return y
```
After scrolling through other answers I found a shorter Python 2 answer but I put the effort into my solution so might as well throw it here. ¯\\_(ツ)\_/¯
[Answer]
# REXX, 46 bytes
```
arg a
do n=a by a until reverse(n)=n
end
say n
```
[Answer]
# [Python 2](https://docs.python.org/2/), 44 bytes
```
x=lambda n,m=0:m*(`m`==`m`[::-1])or x(n,m+n)
```
[Try it online!](https://tio.run/##HYxBCoQwFEP3niJLqx2wVUYo/JOIoOIMCtOvaBf29J2vi4SQ8LLHsGxsU7roN/ppHsHaU@V8kQ9@IBLrnHuZXm0HrlzGklUKnzOcIHRGw2qYt6jVaO5spKurO9m66bOvcBEr42Ec9mPlIE9RpT8 "Python 2 – Try It Online")
I know that the question was posted over six months ago, but this was shorter than any other Python submission.
[Answer]
## [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 29 bytes
```
:{c=a*q~!c$=_f!c$||_Xc\q=q+1
```
Explanation:
```
:      Get cmd line param as number 'a'
{      DO
c=a*q  multiply 'a' by 'q' (which is 1 at the start of a QBIC program) and assign to 'c'
~      IF
!c$    'c' cast to string
=      equals
_f!c$| 'c' cast to string, the reversed
|      THEN
_Xc    Quit, printing 'c'
\q=q+1 ELSE increment q and rerun
       DO Loop is auto-closed by QBIC, as is the IF
```
[Answer]
# [Perl 6](http://perl6.org), 35 bytes
```
->\N{first {$_%%N&&$_==.flip},N..*}
```
```
->\N{first {$_==.flip},(N,N*2...*)}
```
```
->\N{(N,N*2...*).first:{$_==.flip}}
```
## Explanation:
```
-> \N {
  # from a list of all multiples of the input
  # ( deduced sequence )
  ( N, N * 2 ... * )
  # find the first
  .first:
  # that is a palindrome
  { $_ == .flip }
}
```
[Answer]
## Perl 6, 39 bytes
```
my &f={first {.flip==$_},($_,2*$_...*)}
```
(33 not including the `my &f=`)
]