[Question]
  [
Given a positive integer as input, output the smallest positive integer such that appending its digits (in base 10) to the end of the input number will form a prime number.
## Examples
```
1     -->   1
2     -->   3
8     -->   3
9     -->   7
11    -->   3
20    -->  11
43    -->   1
134   -->  11
3492  -->  11
3493  -->   9
65595 -->  19
```
## Rules and Scoring
* This is code golf, so shortest code wins
* Standard rules and loopholes apply
* Use any convenient I/O format
* The largest concatenated number (which is larger than both the input and output) your solution supports must be at least \$2^{53} - 1\$. (This is the largest odd integer that can be represented with double precision floats)
* Leading zeros should not be added to numbers before appending them to the input number
* Primality tests must be exact
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
1ṭVẒɗ1#
```
[Try it online!](https://tio.run/##y0rNyan8/9/w4c61YQ93TTo53VD5v/XhdpVHTWvcgcI6RjoWOpY6hkCGgY6JsY6hsYmOsYmlEYgw1jEzNbU0BQA "Jelly – Try It Online")
## How it works
```
1ṭVẒɗ1# - Main link. Takes n on the left
    ɗ   - Define a dyad f(k, n) from the previous 3 links:
 ṭ      -   Tack; Yield [n, k]
  V     -   Eval; Smash together into a single integer
   Ẓ    -   Is prime?
1    1# - Starting from k = 1, find the first k such that f(k, n) is true
```
[Answer]
# JavaScript (ES6), ~~51~~ 50 bytes
*Saved 1 byte thanks to [@l4m2](https://codegolf.stackexchange.com/users/76323/l4m2)*
Expects the input number as a string.
```
f=(n,k)=>eval('for(d=x=n+k;x%--d;)d')<3?k:f(n,-~k)
```
[Try it online!](https://tio.run/##fc9BDoIwEAXQvafoxkwbrVgKasXqWQilREtaA4aw8uqVGI2kBmb75mf@3PIub4vmen9Q61TpvZbYrg2R57LLawzaNVjJXtqVyfolpSojCsiJX8xRD4v0aYgvnG1dXW5qV2GNgQEahhAURQixRaDxWHmoh1kVY92Hyt6Hp7Lx9qfsr1XCYaYz4wlMZ3kihqdmlH8ViVB3aSpS@GSFfwE "JavaScript (Node.js) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
05AB1E treating strings and integers equal helps again.
```
∞.Δ«p
```
[Try it online!](https://tio.run/##yy9OTMpM/f//Ucc8vXNTDq0u@P/f2MTSGAA "05AB1E – Try It Online") or [Try all cases](https://tio.run/##S0oszvifnFiiYKeQnJ@SqpdfnJiUmapgY6Pg6u/2/1HHPL1zUw6tLvgP5HFxlWdk5qQqFKUmpihk5nGl5HMpKBQUZeaVpCkoqZqmKOjaKSgpqABlFBT08wtK9CFmQSk0423AClPy81L/G3IZcVlwWXIZAhkGXCbGXIbGJlzGJpZGIMKYy8zU1NKUCwA)
```
∞      # in the list of positive integers
 .Δ    # find the first one
   «   # that, when concatenated to the input,
    p  # is a prime number
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 5 bytes
```
;.cṗ>
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3w31ov@eHO6Xb//0cb6hjpWOhY6hgCGQY6JsY6hsYmOsYmlkYgwljHzNTU0jQWAA "Brachylog – Try It Online")
`,.ṗ>` seems like it should work, but `,` seems to be somewhat bugged with unbound variables. [It's a bit hard to tell why](https://github.com/JCumin/Brachylog/blob/2efca3d804ee8a30c231bf5974d1e9d6dfae267c/src/transpile.pl#L482).
```
;.c      The input's concatenation with the output
   ṗ     is a prime number
    >    greater than the output.
```
Uses `>` rather than `∧` so as to force the output to be an integer--otherwise, it would be an empty list for prime inputs.
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~9~~ 8 bytes
Saved 1 byte thanks to Leo
```
ḟöṗr+⁰s1
```
[Try it online!](https://tio.run/##ARsA5P9odXNr///huJ/DtuG5l3Ir4oGwczH///8iMiI "Husk – Try It Online")
Explanation:
```
ḟöṗr+⁰s
ḟ         Find first number at least
       1  1 such that
      s   when it's converted to a string,
    +⁰    and appended to the input
   r      and read as an integer,
  ṗ       the result is prime
```
[Answer]
# [R](https://www.r-project.org/), ~~64~~ ~~62~~ ~~61~~ 60 bytes
```
function(n){while(sum(!(x=n*10^nchar(+F)+F)%%1:x)>2)F=F+1;F}
```
[Try it online!](https://tio.run/##Zc5NCsIwEAXgvaeoSGFiKXTyo0ZJlzmGIMXQQo1QLRbEs8ekim1wGGbx8XhM54xyprfVvblasOT5qJv2DLf@AksYlF1jcbRVfeog08RvmuJ@ICUlWukMD/rlDCBZJWHyvPQXFwZoJMzL7k9kJFsv@C2aMrSYCYZmzuaZIMj4SFOGcTk@EAn7SSK9bISQwtMnI90b "R – Try It Online")
*-1 byte thanks to [@Dominic](https://codegolf.stackexchange.com/users/95126/dominic-van-essen)'s idea and then another one (in both versions).*
### [R](https://www.r-project.org/), ~~60~~ 59 bytes
```
function(n){while(sum(!(x=n*10^nchar(F)+F)%%1:x)>2)F=F+1;F}
```
[Try it online!](https://tio.run/##Zc5LCsIwEIDhvaeoSGFiKXTyUKOkyxxDkGJooUaoFgvi2WNSxTY4i1l8/AzTOaOc6W11b64WLHk@6qY9w62/wBIGZddYHG1VnzrQJNMkTXE/kJISrXSGB/1yBpCskjB5XvqNCwM0EuZl9ycykq0X/B6aGlrMBMNlzuZNEGR8pKlhXI4PRMJ@kkgvGyGk8PRppHsD "R – Try It Online")
Slower version from [@Dominic](https://codegolf.stackexchange.com/users/95126/dominic-van-essen).
Abuses the fact that `n*10^5` will never be prime (but checks it in the first iteration, that's why it's so slow).
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 8 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
É3º╩(\╝░
```
[Run and debug it](https://staxlang.xyz/#p=9033a7ca285cbcb0&i=1%0A2%0A8%0A9%0A11%0A20%0A43%0A134%0A3492%0A3493%0A65595&m=2)
## Explanation
```
wi;i\$e|p!
w while
 |p! end result is not prime, do:
 i push index
 ;i push input and index again
\$      stringify
      e     convert to int
           final index is implicitly output
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
ÈsiU j}a
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=yHNpVSBqfWE&input=NjU1OTU)
```
ÈsiU j}a     :Implicit input of integer U
È            :Function taking an integer as an argument
 s           :  Convert to string
  iU         :  Prepend U and convert back
     j       :  Is prime?
      }      :End function
       a     :Get the first integer >=0 that returns true
```
[Answer]
# [Python 3](https://docs.python.org/3/), 82 bytes
```
def x(n,i=1):k=int(f"{n}{i}");return all(k%j for j in range(2,k))and i or x(n,i+1)
```
[Try it online!](https://tio.run/##HY7RCoMwDEXf9xVhMGhYHlar23T0S4YPgrpVJUrpxE389q6VcC@BnHvJ9HXvkZX3ddPCIpiMllj02rAT7XHlbTXbER@2cR/LUA2D6E8dtKOFDgyDrfjViIR6xIprMBAOe8tZoo/UTC5yPzOJp6SE7pSTDMuFUkVSpaTSPImm6JpleVZSwFSYW1AA5W4ypvISiwNMNr4WamkRM2rt0P8B "Python 3 – Try It Online")
-30 bytes thanks to @Manish Kundu, @MarcMush and @ophact
[Answer]
# [J](http://jsoftware.com/), 22 bytes
```
>:@]^:(0 p:,&.":)^:_&1
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/7awcYuOsNAwUCqx01PSUrDTjrOLVDP9rcnGlJmfkKxgq2CqkKRhCOMZgjhEyxwLCMQdzLJFlDKGaDCFGGBkgG2hijCJpaGyCwjc2sYTaYgnjwzRABMxMTS1N/wMA "J – Try It Online")
Increment counter `>:@]` while `^:_` original number catted with counter `,&.":` is not prime `0 p:`, with counter starting at 1 `&1`.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 6 bytes
```
fP_s+z
```
[Test suite](http://pythtemp.herokuapp.com/?code=fP_s%2Bz&test_suite=1&test_suite_input=1%0A2%0A8%0A9%0A11%0A20%0A43%0A134%0A3492%0A3493%0A65595&debug=0)
Fairly different approach to the existing Pyth answer.
Explanation:
```
fP_s+z  | Full code
fP_s+zT | with implicit variables
--------+-----------------------------------
f       | first positive integer T such that
    +zT | input and T concatenated
   s    | as an integer
 P_     | is prime
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 58 bytes
```
->n,r=1{(2...x=([n,r]*'').to_i).any?{|c|x%c<1}?f[n,r+1]:r}
```
[Try it online!](https://tio.run/##FYlLCsIwFACv4kba6vPhy0eMGHuQEKQWAl1YS2ghJcnZY7sZZhi/fNbidLm8RvCaYs0QMejabGlPVdXg/HsPDXbj2sbUp3Dsn5Rbt/8z2YfPxRAwuIMC2uQKggNxAVwotoPDTUolLX67KaaQpoMzwebyBw "Ruby – Try It Online")
[Answer]
# [Lyxal](https://github.com/Vyxal/Vyxal), 7 bytes
```
≬?pæṅJṅ
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=%E2%89%AC%3Fp%C3%A6%E1%B9%85J%E1%B9%85&inputs=10&header=&footer=)
Uses magic. -1 thanks to @vyxal.
[Answer]
# [Julia 0.4](http://julialang.org/), 39 bytes
with julia 0.4 for `isprime` and `parse`
```
>(x,n=1)=isprime(parse("$x$n"))?n:x>n+1
```
[Try it online!](https://tio.run/##JY3BCgIxDETv@Yqw7KFFD3bbFSu0foh4WLBCZY1LW6F/X2vM4YVJmJnnZ41La17UPTklXcxbiq8gtiXlIIaxjjRIeaFz9bRTrYRcMjq8gsI@MCGvE9P@hVL8ObAwmk/adGpjJ6aG4zzbGW7weCcsGAk5GH6W3k9lJVHQefSiSAmB7u0L "Julia 0.4 – Try It Online")
[Answer]
# JavaScript, 65 bytes
```
f=(n,x=1)=>[...Array((i=n+x)-2)].every((_,e)=>i%(e+2))?x:f(n,x+1)
```
Feel like this is way too long for some reason. I'm not very good at primality testing, so that takes up the vast majority of my code. Basically checks if every number between 2 and `n+[x]` [the number with x appended at the end] yields a nonzero remainder when it divides `i` [`n+[x]`]. If so, return `x`, otherwise call `f` again.
*-4 bytes thanks to @Arnauld.*
*saved 2 more bytes by taking the input number as a string.*
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 13 bytes
```
W!P_s+z=+Z1;Z
```
[Try it online!](https://tio.run/##K6gsyfj/P1wxIL5Yu8pWO8rQOur/fzNTU0tTAA "Pyth – Try It Online")
# Explanation
```
Z     # Set to 0 by default
z     # Input, taken as a string
=Z+Z1 # Increment Z by 1 and assign Z to it
s+z   # Concatenate z with and convert to integer
W!P_  # While it is not prime
;Z    # Print Z after the while loop finishes
```
*thanks Citty for -1 byte*
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 48 bytes
```
(k=0;While[!PrimeQ[10^⌊Log10@++k+1⌋#+k]];k)&
```
Increasing k until n\*floor(10^(Log10(k)+1)+k) is prime  
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277XyPb1sA6PCMzJzVaMaAoMzc1MNrQIO5RT5dPfrqhgYO2dra24aOebmXt7NhY62xNtf9ARXklCvoO6foO1YY6RjoWOpY6hkCGgY6JsY6hsYmOsYmlEYgw1jEzNbU0rf3/HwA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Python 3.8](https://docs.python.org/3.8/), 80 bytes
```
f=lambda n,a=0:math.perm(p:=int(n+str(a)))**2%-~p<1and f(n,a+1)or-~a
import math
```
[Try it online!](https://tio.run/##NU/hToQwDP7PUzQxhvVumBsD7yDOF1F/TNgCORnLmIlKuFdHNrFp2n7N1/ar/fbdaPjFunXV4kMO760EQ6U41YP03YNVbiC2Fr3xxBwn74hExMMhv89u9olJ04ImG//IcHTZTSb9YEfnIQyvXk1@AgGEUcgpXChUFFgAJwoF32peINxR4EWVx7j1HsuyKjFRX1Y1XrX7OI9@jjFsYHtifzsrTJpONVflAj99/czPRZNSiBXjKSZ6dOCpgt7AT2/JIC3ZvqFRIlL4P4d1ApsF1Zp4jMC68L1OZ79A9gzztMC8X3tRQkxvS4rrLw "Python 3.8 (pre-release) – Try It Online")
Inputs \$n\$ as a string and returns the smallest positive integer that makes a prime when appended to \$n\$.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 53 bytes
```
.+
_;$&;_10**
+`((.+;).+);(__+)\3+$
_$1;$($1$.2)*
\G_
```
[Try it online!](https://tio.run/##DcYxCoAwDAXQ/Z8jStJAMdZByQF6iUJ0cHBxEO9ffdN7zve6D@sD171nRTiNHjalBN2Zs7pkFecIlVaUEGROTEZ5loRWo3fDjBUb7M@EpcDK8gE "Retina – Try It Online") Link includes less slower test cases. Explanation:
```
.+
_;$&;_10**
```
Create a working area with the suffix in unary (initially 1), the input prefix, and the current resulting integer in unary (initially one more than ten times the input).
```
((.+;).+);(__+)\3+$
```
Match the suffix and prefix, the prefix, and a factor of the resulting integer.
```
_$1;$($1$.2)*
```
Increment the suffix, keeping the prefix, and calculate the new integer. `$1` actually contains the unary suffix as well as the prefix, but Retina's `*` operator only considers the numeric portion of the parameter. Additionally, the separator is included in the capture of the suffix, thus automatically incrementing it when its length is taken.
```
+`
```
Repeatedly increment the suffix until a prime number is found.
```
\G_
```
Convert the suffix to decimal.
[Answer]
# [Perl 5](https://www.perl.org/), 54 bytes
```
sub{$i=pop;$n=1;$n++while(1x"$i$n")=~/^(11+?)\1+$/;$n}
```
[Try it online!](https://tio.run/##ZZDdTsIwGIbPdxWf41PWrILdmDpmg/chSoJ22ABrHSVAAA@5AC/RG5kdW5yLPVj6Pu9P0mmRL6JiucOUF6v1dI@Sa6UTzDizH9/fvMuF8NjWRYmZS/hn/8VjzB@RMfOxbyPHInFsEdK9h5KiIfxxklygORy8WS502TPuJU4eGA16PZQ9NNeMjNIq7TMyRHN0UpV7DtjzBIwCg2daq4BC2Kj7loop3DWKsZYZ3NidP0ODsLXLwkHbDwdx8I/YTlyCTkVuoyiObKhk0Fkt1IbCdG1go/L5yiH7c3G5s0/L9NpQFFstXo14s/8EJ0nt4kwZfoVpnSJn3ql5m9o0oFTcrSB8n77gd9StIjqXmYGyDOKjcWEEXTXvwhC6mbXslYJbjo0zWzwWPw "Perl 5 – Try It Online")
# [Perl 5](https://www.perl.org/), 65 bytes
A slightly different approach, but 11 bytes longer:
```
sub f{($i,$t)=@_;!$t||(grep"$i$t"%$_<1,2..$i.$t-1)?f($i,$t+1):$t}
```
[Try it online!](https://tio.run/##ZZDdToMwGIbPdxWf3WegsRLLj8ommfehhmSzLM0mraVkmm2nXoCX6I1gERTJetT3eX@SVguzTZqmqpdQ7H2UDC3N7vP5GdrDwV8boQlKtOQc8zvOwiBAGaC95HRRdOkLTmdoj02hjD8Bdx6AM@DwxHoVMogGdTtSKYObQXE@MsMrt/NvKI5GuzyKx34Up@EJcZ20BdOOXCdJmrhQy2BabdWOwbK2sFNmU03o/qf48u6eVuraMhRvWqyseHZ/gvm8d3GtbFb0GfpLAaXKSAfh6@MT/sqki2gjSwttGcTr4MICPLXxYAZe6Sx3ZUDascfSFY/NNw "Perl 5 – Try It Online")
[Answer]
# Python 2, 73 bytes
```
def f(n,x=1):k=int(n+`x`);return all(k%i for i in range(2,k))or-~f(n,x+1)
```
Takes input as a string (e.g. `f("65595")`)
Thanks to `ovs`
[Answer]
# [Raku](http://raku.org/), 28 bytes
```
{first ($_~*).is-prime,1..*}
```
[Try it online!](https://tio.run/##FcbRCoMgAEDRX7mERIslmRoTVr8ie0gQFgvdS0T7dbe9HM62pOdY1p06MJUjxJTfNMJ/2ouMudtSXJerkrI9S37sVMIzzRwB4c@K8ErcFQM3HOqXHqNR2qCNG/5oRmudncsX "Perl 6 – Try It Online")
]