Python π = 1 + (1/2) + (1/3) + (1/4) - (1/5) + (1/6) + (1/7) + (1/8) + (1/9) - (1/10) ...1748 Euler
What you are approximating is
$$ \pi =\sum_{m=1}^{\infty}\frac{(-1)^{s(m)}}{m},$$
where \$s(m)\$ counts the number of appearances of primes of the form \$4k+1\$ in the prime decomposition of \$m\$, compare 


How can we prove \$\pi =1+\frac{1}{2}+\frac{1}{3}+\frac{1}{4}-\frac{1}{5}+\frac{1}{6}+\frac{1}{7}+\cdots\,\$?


on Mathematics Stack Exchange.

The computation of the factor \$ (-1)^{s(m)} \$ can be done more efficiently: Instead of creating a list of all prime factors of \$m \$, then filtering the list for prime factors of the form \$4k+1\$, and finally counting the filtered list, you can compute the sign while factoring the number:

def sign_for_pi_series(n):
    """ Returns sign for 1/n in the pi series.

    The sign is -1 if n has an odd number of prime factors of the form 4k+1,
    and +1 otherwise.
    """
    s = 1
    i = 2
    while i * i &lt;= n:
        if n % i:
            i += 1
        else:
            n //= i
            if i % 4 == 1:
                s = -s
    if n &gt; 1 and n % 4 == 1:
        s = -s
    return s


The summation then simplifies to

sum_pi = sum(D(sign_for_pi_series(x))/D(x) for x in range(1, iters + 1))
print(sum_pi)