Python 2, 106 bytes
from fractions import*
n=input()
F=k=P=1
while n:b=P%k>0;n-=b;F*=1-Fraction(2*b,k*k+1);P*=k*k;k+=1
print F
The first and fourth lines hurt so much... it just turned out that using Fraction
was better than multiplying separately and using gcd
, even in Python 3.5+ where gcd
resides in math
.
Prime generation adapted from @xnor's answer herehere, which uses Wilson's theorem.