[Question]
  [
Given a decimal number `k`, find the smallest integer `n` such that the square root of `n` is within `k` of an integer. However, the distance should be nonzero - `n` cannot be a perfect square.
Given `k`, a decimal number or a fraction (whichever is easier for you), such that `0 < k < 1`, output the smallest positive integer `n` such that the difference between the square root of `n` and the closest integer to the square root of `n` is less than or equal to `k` but nonzero.
If `i` is the closest integer to the square root of `n`, you are looking for the first `n` where `0 < |i - sqrt(n)| <= k`.
# Rules
* You cannot use a language's insufficient implementation of non-integer numbers to trivialize the problem.
* Otherwise, you can assume that `k` will not cause problems with, for example, floating point rounding.
# Test Cases
```
.9         > 2
.5         > 2
.4         > 3
.3         > 3
.25        > 5
.2         > 8
.1         > 26
.05        > 101
.03        > 288
.01        > 2501
.005       > 10001
.003       > 27888
.001       > 250001
.0005      > 1000001
.0003      > 2778888
.0001      > 25000001
.0314159   > 255
.00314159  > 25599
.000314159 > 2534463
```
Comma separated test case inputs: 
```
0.9, 0.5, 0.4, 0.3, 0.25, 0.2, 0.1, 0.05, 0.03, 0.01, 0.005, 0.003, 0.001, 0.0005, 0.0003, 0.0001, 0.0314159, 0.00314159, 0.000314159
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins.
  
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 34 bytes
```
Min[⌈.5/#+{-#,#}/2⌉^2+{1,-1}]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zgq/DfNzMv@lFPh56pvrJ2ta6yjnKtvtGjns44I@1qQx1dw9pYtf8BRZl5JdHKCrp2CmnRyrGxCmoK@g4K1QZ6ljoKBnqmIMIERBiDCCMw3whEGIIIAzDfACxnABGBCkHFYIIwUZgwVNzY0MTQ1BKqAYkN5dT@BwA "Wolfram Language (Mathematica) – Try It Online")
### Explanation
The result must be of the form \$m^2 \pm 1\$ for some \$m \in \mathbb{N}\$. Solving the inequations \$\sqrt{m^2+1} - m \le k\$ and \$m - \sqrt{m^2-1} \le k\$, we get \$m \ge \frac{1-k^2}{2k}\$ and \$m \ge \frac{1+k^2}{2k}\$ respectively. So the result is \$\operatorname{min}\left({\left\lceil \frac{1-k^2}{2k} \right\rceil}^2+1, {\left\lceil \frac{1+k^2}{2k} \right\rceil}^2-1\right)\$.
[Answer]
# [Python](https://docs.python.org/2/), 42 bytes
```
lambda k:((k-1/k)//2)**2+1-2*(k<1/k%2<2-k)
```
[Try it online!](https://tio.run/##Tc7RDoIgFMbx63qKc@MGFAJHvdDZk1QXtsZyp9A5b3x6EoKtm//4foyNeVtfk0NvLzf/Hj6P5wDUMUbSKOJKIRcCT0aiYNTvVGCPkri30wIEo4OrLtsz6LIJqUOqEIwbQ0yIjlvHO/2TRMkyZs2cvDK1adr04O@cxr07HuZldCtYtv/uCw "Python 2 – Try It Online")
Based on [alephalpha's formula](https://codegolf.stackexchange.com/a/180415/20260), explicitly checking if we're in the \$m^2-1\$ or \$m^2+1\$ case via the condition `k<1/k%2<2-k`.
Python 3.8 can save a byte with an inline assignment.
**[Python 3.8](https://docs.python.org/3.8/), 41 bytes**
```
lambda k:((a:=k-1/k)//2)**2-1+2*(a/2%1<k)
```
[Try it online!](https://tio.run/##TcvRCsIgFMbx63oKbwJdbepxgybtSaoLI6RxlhPZTU9vaArd/PH7HfSf7bU6dfYh2ukWF/N@PA1BTanRE7aSI@McWNNAK4/QUMPhIC/Iol0DQTI7chXdeCKiG1L6FJUCeUOKTBF5i3wTPylUrGLVysWV7OUwlg9/7zLuer/zYXYbtRQZi18 "Python 3.8 (pre-release) – Try It Online")
These beat my recursive solution:
**50 bytes**
```
f=lambda k,x=1:k>.5-abs(x**.5%1-.5)>0 or-~f(k,x+1)
```
[Try it online!](https://tio.run/##TY7BCoMwDIbP8ylyGWjV0qo9KOiLjB10U1bUVtoO9LJXd62rsEM@8n9JIMtmXlJkO58XqQzoTQe2sO6N6h9vpbkUE5@5CSlBiEX7UE/t3D1bGJO1ptXYYJa2nQ5XhDC70hSzqCEgVfoZQrsSU3siFYzABdwILhMgmDkUDrlDduTMgTqQI5NjRn7GK@9OedpTe5/TgrLSH/z1Ptyr4LIoLgzYD6P9Cw "Python 2 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 16 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
nD(‚>I·/înTS·<-ß
```
Port of [*@alephalpha*'s Mathematica answer](https://codegolf.stackexchange.com/a/180415/52210), with inspiration from [*@Sok*'s Pyth answer](https://codegolf.stackexchange.com/a/180424/52210), so make sure to upvote both of them!
[Try it online](https://tio.run/##yy9OTMpM/f8/z0XjUcMsO89D2/UPr8sLCT603Ub38Pz//w30DEwB) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/PBeNRw2z7CoPbdc/vC4vJPjQdhvdw/P/6/yPNtCz1FEw0DMFESYgwhhEGIH5RiDCEEQYgPkGYDkDiAhUCCoGE4SJwoSh4saGJoamllANSGwoJxYA).
**Explanation:**
```
n                 # Take the square of the (implicit) input
                  #  i.e. 0.05 → 0.0025
 D(‚              # Pair it with its negative
                  #  i.e. 0.0025 → [0.0025,-0.0025]
    >             # Increment both by 1
                  #  i.e. [0.0025,-0.0025] → [1.0025,0.9975]
     I·           # Push the input doubled
                  #  i.e. 0.05 → 0.1
       /          # Divide both numbers with this doubled input
                  #  i.e. [1.0025,0.9975] / 0.1 → [10.025,9.975]
        î         # Round both up
                  #  i.e. [10.025,9.975] → [11.0,10.0]
         n        # Take the square of those
                  #  i.e. [11.0,10.0] → [121.0,100.0]
          TS      # Push [1,0]
            ·     # Double both to [2,0]
             <    # Decrease both by 1 to [1,-1]
              -   # Decrease the earlier numbers by this
                  #  i.e. [121.0,100.0] - [1,-1] → [120.0,101.0]
               ß  # Pop and push the minimum of the two
                  #  i.e. [120.0,101.0] → 101.0
                  # (which is output implicitly)
```
[Answer]
# JavaScript (ES7), ~~51~~ 50 bytes
```
f=(k,n)=>!(d=(s=n**.5)+~(s-.5))|d*d>k*k?f(k,-~n):n
```
[Try it online!](https://tio.run/##fc7RDoIgGAXg@57C7oASQf2btmHP4kRa4aBF66r56uRqbhRObrj4DudwbZ@t6@6X2yM1VvbeK4H03mDRbJEUyAlDCAW8G5FLpxu/JJGNJvqkplg6Gnw0vrPG2aGngz0jhRitk8/BOMmyJN/8M6xzGXIRcbHOOQQMMYevq4j5z9cOkbOwnTMeB4qwoIoXGA8DsFTxHZk32OIKLznUcwn4Nw "JavaScript (Node.js) – Try It Online")
(fails for the test cases that require too much recursion)
---
# Non-recursive version, ~~57~~ 56 bytes
```
k=>{for(n=1;!(d=(s=++n**.5)+~(s-.5))|d*d>k*k;);return n}
```
[Try it online!](https://tio.run/##hc9JDoMgAIXhfU9hd6BRQcRqDN7FODStBhq13XS4up0citDIhs2X98MxvaRt1hxOnc1FXvQl6yuWXEvRAM5wvAU5Ay2zLG6aDoXWA7T264a33MyTyqxiGDdFd264we99Jngr6sKpxR6UADmRMRwIDdc1vM0S0DXgy4AogKwBj0qAqkBeCBWAF48MFIHkBkZYJUQeCdUOwjKhupkxNZaQFhFpaBfqamNuqumnhuDc@8OIVHwndc0h@tPUzhHsYxrNjur@@DUTiSLtsz5qRMT3A9I/AQ "JavaScript (Node.js) – Try It Online")
Or for **55 bytes**:
```
k=>eval(`for(n=1;!(d=(s=++n**.5)+~(s-.5))|d*d>k*k;);n`)
```
[Try it online!](https://tio.run/##hc/PDoIgAMfxe09hN9CpIGI6h8@iE22lg6bNU@vV7Z9mCE0uXD77feFcDEVfdqfL1RWSV2PNxoZl1VC0IK9lBwTD6R5wBnrmOMK2PQqdO@jd5w1v3OZZYzcpTEUOx1KKXraV18ojqAHyEms6EFq@bwW7NaBbIFQB0QDZAgFVANWBuhBrAK8eGWkCqQ2MsE6IOhLrHYRVQk0zc2ouISMiytAhNtXm3LdmnpqCS@8PI0rxlTQ1p@hP0zhHcIhpsjhq@uPHfEmSGJ/1VjMiYRiR8QE "JavaScript (Node.js) – Try It Online")
(but this one is significantly slower)
[Answer]
# [J](http://jsoftware.com/), ~~39~~ 29 bytes
```
[:<./_1 1++:*:@>.@%~1+(,-)@*:
```
NB. This shorter version simply uses @alephalpha's formula.
[Try it online!](https://tio.run/##hdC9CsIwEMDxvU9xCFLtR8w1TU2DlYLg5OTq4CAWcfENfPWqmEvJBTGQ5fhx/7T3cSbSAToLKRQgwb5vKWB3POzHk92I1RkB89xmtt@Kfv7EfFGUyz6z4zJJrpfbAyrwp4MBpGinwQ@huVBc1H@F4kJzUWkmTCSilzZMIBcoMRSSVypjmFBcaL/ECYwqkmZOTBm3Y22oQ0JFFVpCAuOKG5LwGap8MiYQKq58l3iBTGj@P7BG3Qaibdm3ECGh6rpR4TscSVwsGV8 "J – Try It Online")
## 39 bytes, original, brute force
```
2(>:@])^:((<+.0=])(<.-.)@(-<.)@%:)^:_~]
```
[Try it online!](https://tio.run/##hdBBC4IwFMDxu5/iEYSTcmxus21oBEGnTt2tQyTRpW/QV19Ge4pvRIIenj/ef/oIC5730HrIYQ0C/HCXHPan4yFUbOt3XXH2jDUrLtquYA0vebFjZTM8l354dXl1ociy2/X@hArGq4UeBHfT4IcwVCgq9F@hqDBUVIYIm4jkpDURkgop5FwIWqmsJUJRYcYlUcikInAWxZSJOzYWOyhUUsElKGRaiUMUYwYrn4ydCZVWvktGIYkw9H9ILY2bCefItyBBobSu1fwckWThDQ "J – Try It Online")
Handles all test cases
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~18~~ 16 bytes
-2 bytes from [Shaggy](https://codegolf.stackexchange.com/users/58974/shaggy)
```
_=¬u1)©U>½-½aZ}a
```
[Try it online!](https://tio.run/##y0osKPn/P9720JpSQ81DK0PtDu3VPbQ3Mao28f//aD1LHT1THT0THT1jHT0jIMtIR89QR88AyDIAihiA2GAOmAfhQvgQAbCIsaGJoaklWBGcBWXGcunmAgA "Japt – Try It Online")
[Answer]
# Pyth, ~~22~~ 21 bytes
```
hSm-^.Ech*d^Q2yQ2d_B1
```
Try it online [here](https://pyth.herokuapp.com/?code=hSm-%5E.Ech%2ad%5EQ2yQ2d_B1&input=0.12345&debug=0), or verify all the test cases at once [here](https://pyth.herokuapp.com/?code=hSm-%5E.Ech%2ad%5EQ2yQ2d_B1&test_suite=1&test_suite_input=0.9%0A0.5%0A0.4%0A0.3%0A0.25%0A0.2%0A0.1%0A0.05%0A0.03%0A0.01%0A0.005%0A0.003%0A0.001%0A0.0005%0A0.0003%0A0.0001%0A0.0314159%0A0.00314159%0A0.000314159&debug=0).
Another port of [alephalpha's excellent answer](https://codegolf.stackexchange.com/a/180415/41020), make sure to give them an upvote!
```
hSm-^.Ech*d^Q2yQ2d_B1   Implicit: Q=eval(input())
                  _B1   [1,-1]
  m                     Map each element of the above, as d, using:
           ^Q2            Q^2
         *d               Multiply by d
        h                 Increment
       c      yQ          Divide by (2 * Q)
     .E                   Round up
    ^           2         Square
   -             d        Subtract d
 S                      Sort
h                       Take first element, implicit print
```
*Edit: Saved a byte, thanks to Kevin Cruijssen*
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~34~~ ~~33~~ 29 bytes
*-1 byte thanks to Grimy*
```
{+(1...$_>*.sqrt*(1|-1)%1>0)}
```
[Try it online!](https://tio.run/##VYxRC4IwFEaf268YUuGMLrvOmXtof0QkghQCy9IgZPnbl5nl3Ns59zu75XUZ20tL1wXdW7PxEQCWBx1Ac68fgY@vLbIVas46W1Q19cvzNW@0hmdVnxpGDVk0x5Z6pvAh5RnrqIE0zDqPdBYU/T1NQwJyjpGDgoCYYygnlD0614QAul/FBLizRo69EM4g6QuOjpDD5B99Gv5VYhrtkqETGKFUYyeHzWgGodQb "Perl 6 – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 27 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
```
⌊/0~⍨¯1 1+2*⍨∘⌈+⍨÷⍨1(+,-)×⍨
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1FPl75B3aPeFYfWGyoYahtpAZmPOmY86unQBrIObwcShhraOrqah6cDmf/THrVNeNTb96hvqqf/o67mQ@uNH7VNBPKCg5yBZIiHZ/D/R72r0g6tMNCz1FEw0DMFESYgwhhEGIH5RiDCEEQYgPkGYDkDiAhUCCoGE4SJwoSh4saGJoamllANSGwoBwA "APL (Dyalog Unicode) – Try It Online")
Monadic train taking one argument. This is a port of [alephalpha's answer](https://codegolf.stackexchange.com/a/180415/74163).
### How:
```
⌊/0~⍨¯1 1+2*⍨∘⌈+⍨÷⍨1(+,-)×⍨ ⍝ Monadic train
                         ×⍨ ⍝ Square of the argument
                   1(+,-)   ⍝ 1 ± that (returns 1+k^2, 1-k^2)
                 ÷⍨         ⍝ divided by
               +⍨           ⍝ twice the argument
             ∘⌈             ⍝ Ceiling
          2*⍨               ⍝ Squared
     ¯1 1+                  ⍝ -1 to the first, +1 to the second
  0~⍨                       ⍝ Removing the zeroes
⌊/                          ⍝ Return the smallest
```
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), ~~89~~ ~~85~~ 71 bytes
```
k=>{double n=2,p;for(;!((p=Math.Sqrt(n)%1)>0&p<k|1-p<k);n++);return n;}
```
[Try it online!](https://tio.run/##hY/BS8MwFMbv@StiUZew9tF062Fk7U1hoDjcwIuX2KasbLzWNPUy97fXrBFREPYOye/73sfjvaKLiq4e7nsslmXTvx106L@8yoZ9lh@9opglYSurxjB5xVibPSq7g827sQz5jeB5fNsu958ici@XOJ1yabTtDVKUp0GSF1Nb/VCjZsEK297S/@qpt64V8D/x6EKd424trYod@1CGKlojXSE8a1VumzssGYdNe6gtm7zihPNfs6@DowojkZ7cmRXzh8JamU4zxXnoGm74AAsCKYE5gRmBxFFCQBCIHcXOic88ilF56bU3Rmcm5iJdjKEf@sYv "C# (Visual C# Interactive Compiler) – Try It Online")
-4 bytes thanks to Kevin Cruijssen!
[Answer]
# [Java (JDK)](http://jdk.java.net/), ~~73~~ 70 bytes
```
k->{double i=1,j;for(;(j=Math.sqrt(++i)%1)==0|j>=k&1-j>=k;);return i;}
```
[Try it online!](https://tio.run/##fZA9b8MgEIZn@1ewtAIlRjgfQ4IcqUPHqEPGqgO1aYK/C@dIkevf7oJNqkxleI/3uTt0Ry6uIsqzYlRV22hAufW0A1XSF63FzfAwbLvPUqUoLYUx6ChUjfow8NCAABuujcpQZVP4BFrV5/cPJPTZEFcZZI2tlRaBNJAKIw1KUM/obokY3TrZOFk7WU1@5SR2wibPphybiUee3eGd3rHn63gTb3e@4eHuzcDtfPOi1ICWosJ/QxJaiRaPRXTo5w2QSuJlzr8ajTnOk6OACzXfGvBiochTTJKE/eSHpHiOIxc44VpCp2uk@DAGAfr3EGrffRXp5U1nUssMn24GZEWbDvb71v4plDWx0w7hMP4C "Java (JDK) – Try It Online")
`-3 bytes` thanks to @ceilingcat
[Answer]
# Java 8, 85 bytes
```
n->{double i=1,p;for(;Math.abs(Math.round(p=Math.sqrt(i))-p)>n|p%1==0;i++);return i;}
```
[Port of *EmbodimentOfIgnorance*'s C# .NET answer.](https://codegolf.stackexchange.com/a/180417/52210)
[Try it online.](https://tio.run/##TZA7b8MgFIX3/IqrSJVAjhHOY0iQs3ROloxRBmKTltTBFHCqKvVvd4HgqsvRPR@Pc@DK7zy/1h9D1XBrYcelekwApHLCXHglYB8sQN1250ZAhdKgMPO8n3ixjjtZwR4UlIPKt4@0RZbFTLNLaxDbcfdO@NmiOJi2UzXSZTT20zgkMc413qof/VKUJWUyyzAzwnVGgWT9wEKO9rf6nBR3b2UNN18XHZyR6u14Ao6fXUNk6uCEda/cCtiAEl/pFcfTg5L1DChZBVkGWQSZRz8PUgSh0dO4Rp8kocRGONIRJ74olsVqnQ78m5PpcawLcPi2TtxI2zmi/Vtco9BYPJtuYJopUv0RnH6@H34B)
The `Math.round` can alternatively be this, but unfortunately it's the same byte-count:
```
n->{double i=1,p;for(;Math.abs((int)((p=Math.sqrt(i))+.5)-p)>n|p%1==0;i++);return i;}
```
[Try it online.](https://tio.run/##TZDBb8IgFMbv/hUvJksgtYSqPSipl5314tF4wBY3XKUMqMvS9W/voNJlly/v/YD3fY8bf/D0Vn0MZc2thT2XqpsBSOWEufJSwCG0AFXTXmoBJYqFwszzfubFOu5kCQdQUAwq3XXxiiyyhWbXxiC25@6d8ItFyA/GCOliJPbTOCQxTkiOU4136ke/ZEVBmUwSzIxwrVEgWT@w4KP9VO8T7R6NrODu46KjM1K9nc7A8TNrsIwZnLDulVsBW1DiK25xOneUbBZASR5kHWQVZDn2yyBZEDr2dDyjTxJRZBOc6IQjX2XrLN/EB//q2PR4jAtw/LZO3EnTOqL9Lq5WaAqezLcwTxQp/wiOP98Pvw)
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), 16 bytes
```
²_b*α)½╠ü²1bαm,╓
```
[Try it online!](https://tio.run/##y00syUjPz0n7///QpvgkrXMbNQ/tfTR1weE9hzYZJp3bmKvzaOrk///1LLn0TLn0TLj0jLn0jIAsIy49Qy49AwMDY0MTQ1PL/wA "MathGolf – Try It Online")
Not a huge fan of this solution. It is a port of the 05AB1E solution, which is based on the same formula most answers are using. 
## Explanation
```
²                  pop a : push(a*a)
 _                 duplicate TOS
  b                push -1
   *               pop a, b : push(a*b)
    α              wrap last two elements in array
     )             increment
      ½            halve
       ╠           pop a, b, push b/a
        ü          ceiling with implicit map
         ²         pop a : push(a*a)
          1        push 1
           b       push -1
            α      wrap last two elements in array
             m     explicit map
              ,    pop a, b, push b-a
               ╓   min of list
```
[Answer]
# [Forth (gforth)](http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/), 76 bytes
```
: f 1 begin 1+ dup s>f fsqrt fdup fround f- fabs fdup f0> fover f< * until ;
```
[Try it online!](https://tio.run/##VY3LDoIwEEX3fsUNSw3NlMeiYvgXEQZJTMEW/H0saW3j6uTeMw@ezfrMRz6w71cwJLphnDTkBf22wLYMtm@zgo/IZt50D87B986Gjlrw/BkM@IYzNr1OLzTu2OK9JCh3loXpF4gMyFtk7pPAw6A5kVCDGyVRe1QepUcR2sJDelBoKUzRr48imqSSSzLaUlayVnH5L6W4fwE "Forth (gforth) – Try It Online")
### Explanation
Starts a counter at 1 and Increments it in a loop. Each iteration it checks if the absolute value of the counter's square root - the closest integer is less than k
### Code Explanation
```
: f                   \ start a new word definition
  1                   \ place a counter on the stack, start it at 1
  begin               \ start and indefinite loop
    1+                \ add 1 to the counter
    dup s>f           \ convert a copy of the counter to a float
    fsqrt             \ get the square root of the counter
    fdup fround f-    \ get the difference between the square root and the next closes integer
    fabs fdup         \ get the absolute value of the result and duplicate
    f0>               \ check if the result is greater than 0 (not perfect square)
    fover f<          \ bring k to the top of the float stack and check if the sqrt is less than k
    *                 \ multiply the two results (shorter "and" in this case)
  until               \ end loop if result ("and" of both conditions) is true
;                     \ end word definition
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
I have not managed to get anything terser than the same approach as alephalpha  
- go upvote his [Mathematica answer](https://codegolf.stackexchange.com/a/180415/53748)!
```
²;N$‘÷ḤĊ²_Ø+Ṃ
```
**[Try it online!](https://tio.run/##y0rNyan8///QJms/lUcNMw5vf7hjyZGuQ5viD8/Qfriz6f/RPYfbHzWtcf//30DPUkfBQM8URJiACGMQYQTmG4EIQxBhAOYbgOUMICJQIagYTBAmChOGihsbmhiaWkI1ILGhHAA "Jelly – Try It Online")**
### How?
```
²;N$‘÷ḤĊ²_Ø+Ṃ - Link: number, n (in (0,1))
²             - square n        -> n²
   $          - last two links as a monad:
  N           -   negate        -> -(n²)
 ;            -   concatenate   -> [n², -(n²)]
    ‘         - increment       -> [1+n², 1-(n²)]
      Ḥ       - double n        -> 2n
     ÷        - divide          -> [(1+n²)/n/2, (1-(n²))/n/2]
       Ċ      - ceiling         -> [⌈(1+n²)/n/2⌉, ⌈(1-(n²))/n/2⌉]
        ²     - square          -> [⌈(1+n²)/n/2⌉², ⌈(1-(n²))/n/2⌉²]
          Ø+  - literal         -> [1,-1]
         _    - subtract        -> [⌈(1+n²)/n/2⌉²-1, ⌈(1-(n²))/n/2⌉²+1]
            Ṃ - minimum         -> min(⌈(1+n²)/n/2⌉²-1, ⌈(1-(n²))/n/2⌉²+1) 
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 14 bytes
```
_=¬aZ¬r¹©U¨Z}a
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Xz2sYVqscrmpVahafWE&input=LjI)
```
_=¬aZ¬r¹©U¨Z}a     :Implicit input of integer U
_                  :Function taking an integer Z as an argument
 =                 :  Reassign to Z
  ¬                :    Square root of Z
   a               :    Absolute difference with
    Z¬             :      Square root of Z
      r            :      Round to the nearest integer
       ¹           :  End reassignment
        ©          :  Logical AND with
         U¨Z       :  U greater than or equal to Z
            }      :End function
             a     :Return the first integer that returns true when passed through that function
```
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 42 bytes
```
$t=sqrt++$\while($p=abs$t-int$t)>$_||!$p}{
```
[Try it online!](https://tio.run/##K0gtyjH9/1@lxLa4sKhEW1slpjwjMydVQ6XANjGpWKVENzOvRKVE004lvqZGUaWgtvr/fz3Df/kFJZn5ecX/dQsA "Perl 5 – Try It Online")
]