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