f | from decimal import * | f | from decimal import * |
| | | |
| | | |
| def factorial(n): | | def factorial(n): |
n | x = 1 | n | sum = 1 |
| for i in range(2, n + 1): | | for i in range(2, n + 1): |
n | x *= i | n | sum *= i |
| return x | | return sum |
| | | |
| | | |
| getcontext().prec = 10000 | | getcontext().prec = 10000 |
| | | |
| | | |
| def PiGen(): | | def PiGen(): |
| z = 426880 * Decimal("10005").sqrt() | | z = 426880 * Decimal("10005").sqrt() |
n | y = 0 | n | k = 0 |
| x = 0 | | sum = 0 |
| while True: | | while True: |
t | a = Decimal(str(factorial(6 * y) * (545140134 * y + 13591409))) | t | a = Decimal(str(factorial(6 * k) * (545140134 * k + 13591409))) |
| b = Decimal(str(factorial(3 * y) * factorial(y) | | b = Decimal(str(factorial(3 * k) * factorial(k) |
| ** 3 * (-262537412640768000) ** y)) | | ** 3 * (-262537412640768000) ** k)) |
| x += a/b | | sum += a / b |
| yield z / x | | yield z / sum |
| y += 1 | | k += 1 |
| | | |