I wrote this code to show that my reddit post is correct https://www.reddit.com/r/mathematics/comments/cihfeu/this_euler_series_for_π_is_beautiful_and/?utm_source=share&utm_medium=web2x
"After the first two terms, the signs are determined as follows: if the denominator is a cousin of the form 4m – 1, the sign is positive; if the denominator is a cousin of the form 4m + 1, the sign is negative ; For composite numbers, the sign is equal to the product of the signs of its factors.
Basically, it is the harmonic series minus non-Gaussian prime reciprocals and reciprocals whose factors are an odd multiple of non-Gaussian cousins, who beautifully embody quadratic reciprocity. https://en.m.wikipedia.org/wiki/Quadratic_reciprocity "
This is a very, very inefficient way of calculating Pi. However, I think it is the most beautiful. Which is difficult to sell, because Pi's algorithms are practically the most harmonious things.
This formula for Pi is my favorite because it clearly shows how a circle relates to the harmonic series, and how that series relates to the prime number theorem and quadratic reciprocity.
I love all the algorithms for Pi, this is because of his & # 39; vision & # 39; which provides when relating Pi, prime and quadratic numbers.
iters = int(input('Number of Iterations: '))
D = decimal.Decimal
decimal.getcontext().prec = 100
i = 2
factors = ()
while i * i <= n:
if n % i:
i += 1
n //= i
if n > 1:
s = D(0)
for x in range(1, iters):
clist = (int(i) for i in prime_factors(x))
plist = (n for n in clist if n%4==1)
s += 1/D(x)