[Question]
  [
# Single moves
The board is an infinite 2 dimensional square grid, like a limitless chess board. A piece with value N (an ***N-mover***) can move to any square that is a distance of exactly the square root of N from its current square (Euclidean distance measured centre to centre).
For example:
* A 1-mover can move to any square that is horizontally or vertically adjacent
* A 2-mover can move to any square that is diagonally adjacent
* A 5-mover moves like a chess knight
Note that not all N-movers can move. A 3-mover can never leave its current square because none of the squares on the board are a distance of exactly root 3 from the current square.
# Multiple moves
If allowed to move repeatedly, some pieces can reach any square on the board. For example, a 1-mover and a 5-mover can both do this. A 2-mover can only move diagonally and can only reach half of the squares. A piece that cannot move, like a 3-mover, cannot reach any of the squares *(the starting square is not counted as "reached" if no movement occurs)*.
[![1-mover](https://i.stack.imgur.com/VJHUqs.png "1-mover. Proportion reachable: 1")](https://i.stack.imgur.com/VJHUq.png)
[![2-mover](https://i.stack.imgur.com/DQZNgs.png "2-mover. Proportion reachable: 1/2")](https://i.stack.imgur.com/DQZNg.png)
[![3-mover](https://i.stack.imgur.com/Irb9Xs.png "3-mover. Proportion reachable: 0")](https://i.stack.imgur.com/Irb9X.png)
[![4-mover](https://i.stack.imgur.com/8eFbps.png "4-mover. Proportion reachable: 1/4")](https://i.stack.imgur.com/8eFbp.png)
[![5-mover](https://i.stack.imgur.com/2mAWYs.png "5-mover. Proportion reachable: 1")](https://i.stack.imgur.com/2mAWY.png)
[![8-mover](https://i.stack.imgur.com/Ia6Dys.png "8-mover. Proportion reachable: 1/8")](https://i.stack.imgur.com/Ia6Dy.png)
[![9-mover](https://i.stack.imgur.com/ph92ss.png "9-mover. Proportion reachable: 1/9")](https://i.stack.imgur.com/ph92s.png)
[![10-mover](https://i.stack.imgur.com/1NlwDs.png "10-mover. Proportion reachable: 1/2")](https://i.stack.imgur.com/1NlwD.png)
[![20-mover](https://i.stack.imgur.com/RreHys.png "20-mover. Proportion reachable: 1/4")](https://i.stack.imgur.com/RreHy.png)
[![25-mover](https://i.stack.imgur.com/NIB1Ss.png "25-mover. Proportion reachable: 1")](https://i.stack.imgur.com/NIB1S.png)
[![40-mover](https://i.stack.imgur.com/KKdlDs.png "40-mover. Proportion reachable: 1/8")](https://i.stack.imgur.com/KKdlD.png)
[![64-mover](https://i.stack.imgur.com/JZ7r5s.png "64-mover. Proportion reachable: 1/64")](https://i.stack.imgur.com/JZ7r5.png)
[![65-mover](https://i.stack.imgur.com/wnPYrs.png "65-mover. Proportion reachable: 1")](https://i.stack.imgur.com/wnPYr.png)
[![68-mover](https://i.stack.imgur.com/idHbJs.png "68-mover. Proportion reachable: 1/4")](https://i.stack.imgur.com/idHbJ.png)
The images show which squares can be reached. More details on hover. Click for larger image.
* Squares reachable in 1 or more moves are marked in black
* Squares reachable in exactly 1 move are shown by red pieces  
*(apart from the 3-mover, which cannot move)*
What proportion of the board can a given N-mover reach?
# Input
* A positive integer N
# Output
* The proportion of the board that an N-mover can reach
* This is a number from 0 to 1 (both inclusive)
* For this challenge, output as a fraction in lowest terms, like 1/4, is allowed
So for input `10`, both `1/2` and `0.5` are acceptable outputs. Output as separate numerator and denominator is also acceptable, to be inclusive of languages that support neither floats nor fractions. For example, `1 2` or `[1, 2]`.
For the integer outputs (0 and 1), any of the following are acceptable formats:
* For 0: `0`, `0.0`, `0/1`, `0 1`, `[0, 1]`
* for 1: `1`, `1.0`, `1/1`, `1 1`, `[1, 1]`
# Scoring
This is code golf. The score is the length of the code in bytes. For each language, the shortest code wins.
# Test cases
In the format `input : output as fraction : output as decimal`
```
  1 : 1     : 1
  2 : 1/2   : 0.5
  3 : 0     : 0
  4 : 1/4   : 0.25
  5 : 1     : 1
  6 : 0     : 0
  7 : 0     : 0
  8 : 1/8   : 0.125
  9 : 1/9   : 0.1111111111111111111111111111
 10 : 1/2   : 0.5
 13 : 1     : 1
 16 : 1/16  : 0.0625
 18 : 1/18  : 0.05555555555555555555555555556
 20 : 1/4   : 0.25
 25 : 1     : 1
 26 : 1/2   : 0.5
 64 : 1/64  : 0.015625
 65 : 1     : 1
 72 : 1/72  : 0.01388888888888888888888888889
 73 : 1     : 1
 74 : 1/2   : 0.5
 80 : 1/16  : 0.0625
 81 : 1/81  : 0.01234567901234567901234567901
 82 : 1/2   : 0.5
144 : 1/144 : 0.006944444444444444444444444444
145 : 1     : 1
146 : 1/2   : 0.5
148 : 1/4   : 0.25
153 : 1/9   : 0.1111111111111111111111111111
160 : 1/32  : 0.03125
161 : 0     : 0
162 : 1/162 : 0.006172839506172839506172839506
163 : 0     : 0
164 : 1/4   : 0.25
241 : 1     : 1
242 : 1/242 : 0.004132231404958677685950413223
244 : 1/4   : 0.25
245 : 1/49  : 0.02040816326530612244897959184
260 : 1/4   : 0.25
261 : 1/9   : 0.1111111111111111111111111111
288 : 1/288 : 0.003472222222222222222222222222
290 : 1/2   : 0.5
292 : 1/4   : 0.25
293 : 1     : 1
324 : 1/324 : 0.003086419753086419753086419753
325 : 1     : 1
326 : 0     : 0
360 : 1/72  : 0.01388888888888888888888888889
361 : 1/361 : 0.002770083102493074792243767313
362 : 1/2   : 0.5
369 : 1/9   : 0.1111111111111111111111111111
370 : 1/2   : 0.5
449 : 1     : 1
450 : 1/18  : 0.05555555555555555555555555556
488 : 1/8   : 0.125
489 : 0     : 0
490 : 1/98  : 0.01020408163265306122448979592
520 : 1/8   : 0.125
521 : 1     : 1
522 : 1/18  : 0.05555555555555555555555555556
544 : 1/32  : 0.03125
548 : 1/4   : 0.25
549 : 1/9   : 0.1111111111111111111111111111
584 : 1/8   : 0.125
585 : 1/9   : 0.1111111111111111111111111111
586 : 1/2   : 0.5
592 : 1/16  : 0.0625
593 : 1     : 1
596 : 1/4   : 0.25
605 : 1/121 : 0.008264462809917355371900826446
610 : 1/2   : 0.5
611 : 0     : 0
612 : 1/36  : 0.02777777777777777777777777778
613 : 1     : 1
624 : 0     : 0
625 : 1     : 1
```
  
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~144~~ ~~138~~ ~~125~~ ~~74~~ ~~73~~ 70 bytes
```
f=(x,n=2,c=0)=>x%n?x-!c?f(x,n+1)/(n%4>2?n/=~c&1:n%4)**c:1:f(x/n,n,c+1)
```
[Try it online!](https://tio.run/##FYpBDoMgEEX3nmK6sAHBAqYr7ehZzFQaGjMYbIyrXp3S1fvv573nY94phe3TcnwuOXsUp2bsNKGVOJ41T2d7ocn/b@WkEVzfx25ig1@6ur6YbBrqXV8Kw5o1lSoPlY8JxDEnCIDghoIHOGttWUrJCijyHtfltsaXCBq8CFLmHw "JavaScript (Node.js) – Try It Online")
**-4 byte thanks @Arnauld!**
### Original approach, 125 bytes
```
a=>(F=(x,n=2)=>n*n>x?[x,0]:x%n?F(x,n+1):[n,...F(x/n,n)])(a).map(y=>r-y?(z*=[,1,.5,p%2?0:1/r][r%4]**p,r=y,p=1):p++,z=r=p=1)&&z
```
[Try it online!](https://tio.run/##FYzBDoIwEAXvfEUvkJYupTV6ARdu/ATh0CAYDG6bagzw8wineZOXzMv@7KcPk/9m5B7DPuJuseIN8gUILwIrSqla6nYB3RVLTHVzPtKIoiVQSh2aE5DoBLdCva3nK1YhW2u@pdiCAXUDH19qXZg8dG2Ir12aegi4gsej4qWEDQOekiTbXkajC4z/bGATQ2bKA3dmtNbHklJErHf0cfOgZvfkE7CRT0Lsfw "JavaScript (Node.js) – Try It Online")
Inspired by the video [Pi hiding in prime regularities](https://www.youtube.com/watch?v=NaL_Cb42WyY) by 3Blue1Brown.
For each prime factor \$p^n\$ in the factorization of the number, calculate \$f(p^n)\$:
* If \$n\$ is odd and \$p\equiv 3\text{ (mod 4)}\$ - \$f(p^n)=0\$. Because there is no place to go.
* If \$n\$ is even and \$p\equiv 3\text{ (mod 4)}\$ - \$f(p^n)=\frac{1}{p^n}\$.
* If \$p=2\$ - \$f(2^n)=\frac{1}{2^n}\$.
* If \$p\equiv 1\text{ (mod 4)}\$ - \$f(p^n)=1\$.
Multiply all those function values, there we are.
### Update
Thanks to the effort of contributors from Math.SE, the algorithm is now [backed by a proof](https://math.stackexchange.com/questions/3108324/how-much-of-an-infinite-board-can-a-n-mover-reach/3108647#3108647)
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), ~~189~~ ~~185~~ ~~172~~ 171 bytes
```
import StdEnv
$n#r=[~n..n]
#p=[[x,y]\\x<-r,y<-r|x^2+y^2==n]
=sum[1.0\\_<-iter n(\q=removeDup[k\\[a,b]<-[[0,0]:p],[u,v]<-q,k<-[[a+u,b+v]]|all(\e=n>=e&&e>0)k])p]/toReal(n^2)
```
[Try it online!](https://tio.run/##NY3BbsIwEETP5CtWgFCi2KmTFlRVMSd6qNRTOdpOZcBtI2InJE5EJNRPrzGtenirndHuzL5S0jhdH/pKgZalcaVu6tbC1h6ezRDMzayl7NskiRHBrKGMndEoOD/nuEWjH5dzkcVjkVHqD2jXa5YmhPP3HJdWtWBCfqKt0vWgNn3DjpwziXYix4wRRMRTIxDr0eCNEzreXBn3aBcPQlxkVYVcUbOmarFQaxIdRdSIO1u/KVmFpsgit7WytcFkBlZ1tgMKoW9PUiIgjoGl9wjSlecRQUY8S4/XqwfPUkTBhAILb68IptxSmCKY/0szjYDz32DI8V@BcD/7j0p@dg6/vLrNaKQu9158uSUh2uGdw51f9RU "Clean – Try It Online")
Finds every position reachable in the `n`-side-length square cornered on the origin in the first quadrant, then divides by `n^2` to get the portion of all cells reachable.
This works because:
* The entire reachable plane can be considered as overlapping copies of this `n`-side-length square, each cornered on a reachable point from the origin as if it were the origin.
* All movements come in groups of four with signs `++ +- -+ --`, allowing the overlapping tiling to be extended through the other three quadrants by mirroring and rotation.
[Answer]
# Mathematica, 80 bytes
```
d[n_]:=If[#=={},0,1/Det@LatticeReduce@#]&@Select[Tuples[Range[-n,n],2],#.#==n&];
```
This code is mostly reliant on a mathematical theorem. The basic idea is that the code asks for the density of a lattice given some generating set. 
More precisely, we are given some collection of vectors - namely, those whose length squared is N - and asked to compute the density of the set of possible sums of these vectors, compared to all integer vectors. The math at play is that we can always find two vectors (and their opposite) that "generate" (i.e. whose sums are) the same set as the original collection. LatticeReduce does exactly that.
If you have just two vectors, you can imagine drawing an identical parallelogram centered at each reachable point, but whose edge lengths are the given vectors, such that the plane is completely tiled by these parallelograms. (Imagine, for instance, a lattice of "diamond" shapes for n=2). The area of each parallelogram is the determinant of the two generating vectors. The desired proportion of the plane is the reciprocal of this area, since each parallelogram has just one reachable point in it.
The code is a fairly straightforward implementation: Generate the vectors, use LatticeReduce, take the determinant, then take the reciprocal. (It can probably be better golfed, though)
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~126~~ 82 bytes
```
.+
$*
+`^(1(1111)+)(?<!^\3+(11+))(\1)*$
1$#4$*
^(?!((^1|11\2)+)\1?$)1+
0
11+
1/$.&
```
[Try it online!](https://tio.run/##RY8xTsVADET7uQYBbbJSWHttZ1cRovyXiPifSBQ0FIiSu4cJFBRPsdfjmfjz7ev94/W4T5fbMWcME/LtJYnkMW0y5m3HIKsMd8rJtgsn8vcsbNPZj3lcN/kVXgfBPP2/b/s8oeCKla7bRdLz0zytiebj9yp54AoYBXkc5ofjECgqDI7AgoYOKZAKCUiDFqhDA2EIx6JYKhZDK2iCphAz4oR6axA/V@kQTAnO4@wNagwyJWd9WtKZGm0M6aw7Z72iqhEngUpNpabSp0ZHXQrMOsz55Z411tx1PRGicPo7/8Op88a6OQk4/Z3@3nlL4bG8MkSIkopgbqj/AA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
.+
$*
```
Convert to unary.
```
+`^(1(1111)+)(?<!^\3+(11+))(\1)*$
1$#4$*
```
Repeatedly divide by prime factors of the form `4k+1`.
```
^(?!((^1|11\2)+)\1?$)1+
0
```
If the result is neither a square nor twice a square then the result is zero.
```
11+
1/$.&
```
Compute the reciprocal as a decimal fraction.
[Answer]
# Regex (ECMAScript, reciprocal out), ~~256~~ ~~163~~ ~~157~~ ~~94~~ ~~83~~ 82 bytes
*-93 bytes [thanks to Neil](https://chat.stackexchange.com/transcript/message/49175336#49175336)*  
*-6 bytes [thanks again to Neil](https://chat.stackexchange.com/transcript/message/49177733#49177733)*  
This uses the same mathematics as [Shieru Asakoto's JavaScript answer](https://codegolf.stackexchange.com/a/179760/52210).
The input is in unary. Since a pure regex can only return as output a substring from the input (i.e. a natural number less than or equal to the input), or "no match", this regex returns the reciprocal of the proportion of the board that an N-mover can reach. Since the reciprocal of 0 is infinity, it returns "no match" in that case.
**SPOILER WARNING**: For the square root, this regex uses a variant of the generalized multiplication algorithm, which is non-obvious and could be a rewarding puzzle to work out on your own. For more information, see an explanation for this form of the algorithm in [Find a Rocco number](https://codegolf.stackexchange.com/questions/179239/find-a-rocco-number/179420#179420).
This regex first goes into loop identifying all prime factors \$p\$ such that \$p\equiv 1\text{ (mod 4)}\$, and divides the input number by each one as many times as it can. Let \$m\$ be the end result of this. Then, it indirectly tests to see if the prime factorization of \$m\$ (and therefore also the input number) includes any primes \$\equiv 3\text{ (mod 4)}\$ raised to an odd power, by testing to see if \$m\$ or \$m/2\$ is a perfect square. If not, then \$m\$ did include such a prime raised to an odd power, and the regex returns "no match"; otherwise, it returns \$m\$.
(It's now a bit more complicated than that. Due to a golf optimization in the reciprocal-output version, it tests not only \$m\$ and \$m/2\$ for being a square, but also the intermediate result before the division of each \$p\$, if the first test fails. This doesn't change the end result, because if the first perfect square test failed, at least one odd power of a prime \$\equiv 3\text{ (mod 4)}\$ will still be present in the number at every step, and it can't be a square.)
```
^(?=((?=(x+)(?!(\2+)(\2\3)+$)((\2{4})+$))\5|((xx?)(\8*))(?=(\7*)\9+$)\7*$\10)+$)\1
```
[Try it online!](https://tio.run/##XZDPTsJAEIdfpRBCZ1pbWgRU6sLJAxcOerSabGAoq8vS7C5Q@XP1AXxEXwS3iSbEw2Z@2W8n8@288S03My1KG5lSzEmv1uqdPs6aKdp5j1Q8VCXAno06wfkVxgzqU4UI4wbkXVfzbn6NYQvBpUPvVEfM@0eAqho7ehsg1i35TYD5nYMutPI0qd/l6Tno7DG26yerhSoAYyPFjGBwFfUQM8OSbLcUkgAk08TnUigCxAZTGynxUDAZm1IKC37kYyYWAIoVsSRV2CWOusejMFM@BcFKrg1NlIXiOXlB/AN0CdQoHafDGqNd6vWuOVFbLsXc01wVNPSaocwWaw2ZuGeUiTDEg2m3SyduoXZNa4EVa1bNWFNJ3ILAeMXtbAkasdxYYzWI0Pe@P788P4SVU/l1dZP9tOOHF1dDP/XdCkga8v71Ju6vp9M5iQbd/g8 "JavaScript (SpiderMonkey) – Try It Online")  
[Try it online!](https://tio.run/##XZBBbtswEEX3PIViBNHQKh2SImnJquxVF9lk0S6rFhBsRmYrywLFxG5sb3uAHrEXcUdACwRdEG/AP/Pnk9/ql3pYe9cHNvRuY/1u3323P66@7Owh@mibD8ce4LVc3k@vX2FVwniOCYXVDVQSWckqpcktBaxO6jKWtNJngONxhWo2pXQcqeZTWuUoYnFbCT72VeI6vX@ls7D/FLzrGqCzoXVrC@YdU5QWQ8mLw9a1FqAtva03ressUHpTds9tS09N2c6GvnUBYhbTwj0BdGUza23XhC1dyvPZDY/1I7iyr/1gH7oAzWf@hdJ/gn0rdEuxEotRpmHr94fJQ/dSt24T@bpr7CKaJG3xtPdQuPelLVyS0NNwd9dj8ABjVjEG2JWT42TmbW/rAI7OdnVYb8FT2j@HIXhwSRz9/vkrihPYYZS/WXFzLO7j5M3VIhYxfoFtBxv9N8vxrZfLVTDBiUiJMERkRHIiNZOGGMWMJnPJ5opknGWSCKWYUBqJnSojQo9DnAmjiFSCSSWRCqmJxHtpBJEZWubomUsm85SkUrEU3VPUUyOROUvnnCiVM6WRWcYU9mvJmZaSaKXwZEyrnOhMMZ0ZotFLo5fOMSXXxAjOjBBIiUyJwR1G6j8 "JavaScript (SpiderMonkey) – Try It Online") (just the test cases)
```
^
(?=
    (                          # Capture return value, which will just be the value
                               # matched by the last iteration of this loop.
    # Divide tail by every one of its prime factors that's ≡1 mod 4, as many times as
    # possible.
        (?=
            (x+)               # \2 = quotient
            (?!(\2+)(\2\3)+$)  # Assert divisor is prime
            ((\2{4})+$)        # Assert divisor ≡1 mod 4; \5 = tool to make tail = \2
        )\5                    # tail = \2
    |
    # When the above alternative has been done as many times as possible:
    # Test if tail or tail/2 is a perfect square. If this test fails, the regex engine
    # will backtrack into the division loop above, and run the same perfect square
    # test on every previous number (effectively "multiplying" it by each previous P
    # in reverse, one at a time). This will not cause a failure of the test to change
    # into a success, however, because the odd power of a prime ≡3 mod 4 will see be
    # present in the number at every step. Allowing this backtracking to happen is a
    # golf optimization, and it does make the regex slower.
    # Failure of this perfect square test results in returning "no match" and indicates
    # a return value of zero.
        (                      # \7 = \8 * sqrt(tail / \8)
            (xx?)              # \8 = control whether to take sqrt(tail)
                               #                         or 2*sqrt(tail/2)
            (\8*)              # \9 = \7 - \8
        )
        (?=
            (\7*)\9+$          # Iff \8 * (\7 / \8)^2 == our number, then the first match
                               # here must result in \10==0
        )
        \7*$\10                # Test for divisibility by \7 and for \10==0
                               # simultaneously
    )+
    $                          # Require that the last iteration of the above loop was
                               # the perfect square test. Since the first alternative,
                               # the division, always leaves >=1 in tail, this guarantees
                               # that the last step is a successful perfect square test,
                               # or else the result will be "no match".
)
\1                             # Return value (which is a reciprocal)
```
## Regex (ECMAScript+`(?*)`, reciprocal output), ~~207~~ ~~138~~ ~~132~~ bytes
Obsoleted by doing division without capturing the divisor (i.e. is now identical to the above).
## Regex (ECMAScript 2018, reciprocal output), ~~212~~ ~~140~~ ~~134~~ bytes
Obsoleted by doing division without capturing the divisor (i.e. is now identical to the above).
# Regex (ECMAScript, fraction output), 80 bytes
In this version, the numerator is returned in `\10` (zero if unset/NPCG) and the denominator in `\7`.
Unlike the reciprocal output version:
* An input of zero is not correctly dealt with (it returns "no match" just like that version, but unlike it, that does not correspond to an output value of zero).
* If the perfect square test fails, it does not backtrack into the division loop, so this version is more efficient in execution time.
The big downside of an output specification like this is that it isn't contained in the program itself.
```
((?=(x+)(?!(\2+)(\2\3)+$)((\2{4})+$))\5)*((((x)x?)(\9*))(?=(\8*)\11+$)\8*$\12|x)
```
[Try it online!](https://tio.run/##TU/LcsIwDPyVwDBEiktIUqAtqcmpBy4c2iPh4AET3BqTsQ2kPK79gH5if4Q6nTKDDtJKuxqt3tmOmbkWpe2YUiy4Xm/UB/@8aKr43nvlxUtVAhzoqBtcADIKFUHIGpAnruZJfo@kheDQsXeuIeZ9DMBFhVXmFE8BYr2WPwaYx7FTONTK4@RU4SXoHjC0mzerhSoAQyPFnMPgrtNDTA2N0v1KSA4gqeZsIYXigNigaislHgsqQ1NKYcHv@JiKJYCiRSi5KuwKR8npJMyETUDQkmnDx8pCMY1miFeC3xJqFGfxsKbRrvRm3xyrHZNi4WmmCj70mkSmy42GVDxTngpC0B1c02bVDDUvObMgMFwzO1@BRjyadrt0T1mo/4jTcmuN1SCI7/18fXs@AVhP42iW/eV/z8MIiRs/XHtK48z3h37XJzdTZzA9ny9RZ5D0fwE "JavaScript (SpiderMonkey) – Try It Online")  
[Try it online!](https://tio.run/##TU/BctowEL3rKwiTiXdxBZYsCRtXcOohlxzaY5yDBxSj1hiP7QQ3wLUf0E/sj9Cl08xEM9Jb7Xv7dvd78Vp069Y3Pe8av3Htbl//cD8vra3dYfTVlV@GBuDNLmeTC8DKwhAirG4gl4S5zGMMbxEoOqrzNcRc4wToDDisSJFOEK9leTLBXAhSUHSbC3ka8DKZveG033/rW1@XgNOu8msH5hNXiFlno@yw9ZUDqGzrik3laweIN7Z@qSo8lraadk3lewh4gJl/BqhtOa1cXfZbXMrTyXcPxQN42xRt5@7rHsrH6AnxnXAfiXopVmJxpbHftvvD@L5@LSq/GbVFXbrFaBxW2fO@hcx/ti7zYYjUcGfHw3jausYVPXic7op@vYUW8djd3TW0VA/XPUTWvPRd34IPg9GfX79HQQiwexTR0@rf@3/mRYQhpefvf2vFKggWwSwIP2RpwOx8vgguIiZiJgwTCZMRk5pLw4ziRrO55HPFkognkgmluFCakJQqYUJfiyIujGJSCS6VJFSEmknKSyOYTMgyJc9UcpnGLJaKx@QeEx8bSZjyeB4xpVKuNGGScEV6LSOupWRaKboJ1yplOlFcJ4Zp8tLkpVOaMtLMiIgbIQglYcwM9TBS/wU "JavaScript (SpiderMonkey) – Try It Online") (just the test cases)
```
# No need to anchor, since we return a match for all inputs in the domain.
# Divide tail by every one of its prime factors that's ≡1 mod 4
(
    (?=
        (x+)               # \2 = quotient
        (?!(\2+)(\2\3)+$)  # Assert divisor is prime
        ((\2{4})+$)        # Assert divisor ≡1 mod 4; \5 = tool to make tail = \2
    )\5                    # tail = \2
)*
# Test if tail or tail/2 is a perfect square. If this test succeeds, return tail as
# the denominator and 1 as the numerator.
(                          # \7 = denominator output
    (                      # \8 = \9 * sqrt(tail / \9)
        ((x)x?)            # \9 = control whether to take sqrt(tail) or 2*sqrt(tail/2);
                           # \10 = numerator output (NPCG to represent zero)
        (\9*)              # \11 = \8 - \9
    )
    (?=
        (\8*)\11+$         # Iff \9 * (\8 / \9)^2 == our number, then the first match
                           # here must result in \12==0
    )
    \8*$\12                # Test for divisibility by \8 and for \12==0
                           # simultaneously
|
# Failure of the perfect square test results in returning 0/1 as the answer, so here
# we return a denominator of 1.
    x
)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~25~~ 24 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ÆFµ%4,2CḄ:3+2Ịị,*/ʋ÷*/)P
```
A monadic link using the prime factor route.
**[Try it online!](https://tio.run/##AS4A0f9qZWxsef//w4ZGwrUlNCwyQ@G4hDozKzLhu4rhu4ssKi/Ki8O3Ki8pUP///zgx "Jelly – Try It Online")**
### How?
```
ÆFµ%4,2CḄ:3+2Ịị,*/ʋ÷*/)P - Link: integer, n               e.g. 11250
ÆF                       - prime factor, exponent pairs        [[2,1], [3,2], [5,4]]
  µ                   )  - for each pair [F,E]:
    4,2                  -   literal list [4,2]
   %                     -   modulo (vectorises)                [2,1]  [3,0]  [1,0]
       C                 -   complement (1-x)                  [-1,0] [-2,1]  [0,1]
        Ḅ                -   from base 2                         -2     -3      1      
         :3              -   integer divide by three             -1     -1      0
           +2            -   add two (call this v)                1      1      3
                  ʋ      -   last four links as a dyad, f(v, [F,E])
             Ị           -     insignificant? (abs(x)<=1 ? 1 : 0)   1      1      0
                */       -     reduce by exponentiation (i.e. F^E)  2      9     625
               ,         -     pair v with that                   [1,2]  [1,9]  [3,625]
              ị          -     left (Ị) index into right (that)     1      1     625
                    */   -   reduce by exponentiation (i.e. F^E)    2      9     625
                   ÷     -   divide                                1/2    1/9  625/625
                       P - product                                 1/18 = 0.05555555555555555
```
---
Previous 25 was:
```
ŒRp`²S⁼ɗƇ⁸+€`Ẏ;Ɗ%³QƊÐLL÷²
```
Full program brute forcer~~; possibly~~ longer code ~~than the prime factor route (I might attempt that later).~~
[Try it online!](https://tio.run/##ATcAyP9qZWxsef//xZJScGDCslPigbzJl8aH4oG4K@KCrGDhuo47xoolwrNRxorDkExMw7fCsv///zgx "Jelly – Try It Online")
Starts by creating single moves as coordinates then repeatedly moves from all reached locations accumulating the results, taking modulo `n` of each coordinate (to restrict to an `n` by `n` quadrant) and keeping those which are distinct until a fixed point is reached; then finally divides the count by `n^2` 
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~27~~ ~~26~~ 25 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ÓεNØ©<iozë®4%D≠iyÈ®ymz*]P
```
Port of [*@ShieruAsakoto*'s JavaScript answer](https://codegolf.stackexchange.com/a/179760/52210), so make sure to upvote him as well!
[Try it online](https://tio.run/##AS8A0P9vc2FiaWX//8OTzrVOw5jCqTxpb3rDq8KuNCVE4omgaXnDiMKueW16Kl1Q//8xOA) or [verify all test cases](https://tio.run/##FYytCsJgFIZvRQYWecPO2fl@BGHFLBaTGBQMC7IgCN9gVbSJFqNVhDVvYF/3InYj8yw84eXlecrjdlfs@1PIk1F3vo@SPMTbqo@P33cRn@17VpRV/LSNjOfd9VWEeGmbcKgmdV0ve/RrAiODwMDCwWMKSkEZyII8OAUbsIUQrMAaOIbL4AQ@hSd4BokoRlFFPMgMtkYsKfrbYQtYGyysyOYP).
**Explanation:**
```
Ó                   # Get all prime exponent's of the (implicit) input's prime factorization
                    #  i.e. 6 → [1,1]      (6 → 2**1 * 3**1)
                    #  i.e. 18 → [1,2]     (18 → 2**1 * 3**2)
                    #  i.e. 20 → [2,0,1]   (20 → 2**2 * 3**0 * 5**1)
                    #  i.e. 25 → [0,0,2]   (25 → 2**0 * 3**0 * 5**2)
 ε                  # Map each value `n` to:
  NØ                #  Get the prime `p` at the map-index
                    #   i.e. map-index=0,1,2,3,4,5 → 2,3,5,7,11,13
    ©               #  Store it in the register (without popping)
     <i             #  If `p` is exactly 2:
       oz           #   Calculate 1/(2**`n`)
                    #    i.e. `n`=0,1,2 → 1,0.5,0.25
      ë             #  Else:
       ®4%          #   Calculate `p` modulo-4
                    #    i.e. `p`=3,5,7,11,13 → 3,1,3,3,1
          D         #   Duplicate the result (the 1 if the following check is falsey)
           ≠i       #   If `p` modulo-4 is NOT 1 (in which case it is 3):
             yÈ     #    Check if `n` is even (1 if truthy; 0 if falsey)
                    #     i.e. `n`=0,1,2,3,4 → 1,0,1,0,1
             ®ymz   #    Calculate 1/(`p`**`n`)
                    #     i.e. `p`=3 & `n`=2 → 0.1111111111111111 (1/9)
                    #     i.e. `p`=7 & `n`=1 → 0.14285714285714285 (1/7)
              *     #    Multiply both with each other
                    #     i.e. 1 * 0.1111111111111111 → 0.1111111111111111
                    #     i.e. 0 * 0.14285714285714285 → 0
 ]                  # Close both if-statements and the map
                    #  i.e. [1,1] → [0.5,0.0]
                    #  i.e. [1,2] → [0.5,0.1111111111111111]
                    #  i.e. [2,0,1] → [0.25,1.0,1]
                    #  i.e. [0,0,2] → [1.0,1.0,1]
  P                 # Take the product of all mapped values
                    #  i.e. [0.5,0.0] → 0.0
                    #  i.e. [0.5,0.1111111111111111] → 0.05555555555555555
                    #  i.e. [0.25,1.0,1] → 0.25
                    #  i.e. [1.0,1.0,1] → 1.0
                    # (and output implicitly as result)
```
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 21 bytes
This program uses the prime factor route. I am indebted to Adám, dzaima, H.PWiz, J.Sallé, and ngn. [The APL Orchard](https://chat.stackexchange.com/rooms/52405/the-apl-orchard) is a great place to learn APL and they are always willing to help
```
(×/÷,3≠4|*∘≢⌸)⍭*1≠4|⍭
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/X@PwdP3D23WMH3UuMKnRetQx41Hnokc9OzQf9a7VMgQLAln/0x61TXjU2/eob6qn/6Ou5kPrjR@1TQTygoOcgWSIh2fw/zQFcyMA "APL (Dyalog Extended) – Try It Online")
**Ungolfing**
Part 2 of this code is the same as in the Dyalog Unicode version below, and so in this explanation, I will focus on `⍭*1≠4|⍭`
```
⍭*1≠4|⍭
      ⍭  Gives us a list of the prime factors of our input.
           Example for 45: 3 3 5
  1≠4|   Checks if each prime is of the form 4k+1.
⍭*       Takes each prime to the power of 1 or 0,
           turning all the 4k+1 primes into 1s.
           Example for 45: 3 3 1
```
---
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~41~~ ~~40~~ ~~36~~ 35 [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")
This program uses the prime factor route. Learned a few tricks while writing this and I am deeply indebted to Adám, dzaima, H.PWiz, J.Sallé, and ngn. [The APL Orchard](https://chat.stackexchange.com/rooms/52405/the-apl-orchard) is a great place to learn APL and they are always willing to help (or this post never would have got off the ground :)
Edit: -1 byte from ngn. -2 bytes from Adám and -2 more from ngn. -1 byte from ngn.
```
{(×/÷,3≠4|*∘≢⌸)p*1≠4|p←¯2÷/∪∧\⍵∨⍳⍵}
```
[Try it online!](https://tio.run/##jVS9blMxFN7vU2QLVND6/NpmZaETEmVkiYSCEJEaVV1Q6QSqEiAVDAhGYKFi6YBQEWPzJn6RcHJtJx2SEA/xyfF3/r9ze8PB3acve4PDZ7PZya3p573p1R1K46/8aieNvqTx9/T@z@3hDrSqYTr7cH2J06u9NPqZRj@epMnvNLpIk18mnM769pwm5@n80/7D9Pb19SWls4/27@DRfft9/GD/YHZskJO51fjbkYn9NPl7r3v4opveven2e88HXVPY89Fp0@lA57gDdqPdbldMorlkN7canKukgLQ8@XKHFgItJmZ5w2k64GoUoOwSWpe7Tuc@IPtzsv5o00G3SAxLYqjVL5bUNGfvQFrPWoAei5rCuhMNVZLzXN0GdyPNAMUJEov6uEowVO0ocMnFaeS1x2A5R2BdGIZaKQj9v72gJUuaTwS0TdNurOHBY6AoqwSDUYEv5o6cyYFcPTAQIgE7jhLUew1ixllrsBuWki3QsQvmGlXIoqFhQvRRIgRuUBeTxJzs5vowFH44Yo/rToOxsgwjLgLEPFPCOgxyQRmilxWCwaTAM@WJc3eotngjgahU4xx671wgcMiRnGcfrQXk1RNYEK0UId1ie8jXuphjmx2L22JhOCzX1Lrf1sGx1rF@RNhIWbW5pWAmgyBuEVMq51sqypLIwltUKoGXcYNsY1B3RsrI202VMnSJWuOrK8x0AZVZMbgYwZMIeYhV2@jiS6WQ18g6Uyjt155gqBxRM83sbnn0Dw "APL (Dyalog Unicode) – Try It Online")
**Ungolfing**
This is a program in two parts:
```
p*1≠4|p←¯2÷/∪∧\⍵∨⍳⍵  Part 1
      p←             We can define variables mid-dfn (a function in {} brackets).
               ⍵∨⍳⍵  We take the GCD of our input 
                       with every member of range(1, input).
            ∪∧\      This returns all the unique LCMs of every prefix
                       of our list of GCDs.
                       Example for 31500: 1 2 6 12 60 420 1260 6300 31500
        ¯2÷/         We divide pairwise (and in reverse)
                       by using a filter window of negative two (¯2).
                       Example for 31500: 2 3 2 5 7 3 5 5
  1≠4|p              Check if the primes are 1 modulo 4 or not
p*                   And take each prime to the power of the result (1 or 0),
                       turning the 4k+3 primes into 1s
                       and leaving any 2s and 4k+3 primes.
                       Example for 31500: 2 3 2 1 7 3 1 1
(×/÷,3≠4|*∘≢⌸)  Part 2
(            )  We apply all this to the filtered array of primes.
         *∘≢⌸   This takes all of our primes to their exponents
                  (the number of times those primes appear in the factorization).
                  Example for 31500: 4 9 1 7
     3≠4|       Then we take each prime modulo 4 and check if not equal to 3.
                  We will only get a falsey if any 4k+3 primes, as an even number of
                  4k+3 primes multiplied together will result in some 4m+1.
                  Example for 31500: 1 1 1 0
   ÷,           We append the results of the above condition check
                  to the reciprocals of the primes in p.
                  Example for 31500: (1/2) (1/3) (1/2) 1 (1/7) (1/3) 1 1 1 1 1 0
 ×/             We multiply it all together, resulting in a positive fraction or 0
                  depending on our condition check.
                  Example for 31500: 0
                We return the results of all our checks implicitly.
```
]