Created
March 15, 2018 02:16
-
-
Save chuntaro/f6da0ca68beaadc86f9f9a70cb17bfb6 to your computer and use it in GitHub Desktop.
円周率をマチンの公式を使って10000桁計算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 出力結果は3の後ろに小数点が無いのと最後の4桁は未収束の為除いたものが正しい値 | |
| import time | |
| def mpiarccot(x): | |
| base = 10 ** (10000 + 4) | |
| a = x | |
| b = 1 | |
| pos = base // (a * b) | |
| s = 0 | |
| while pos > 1: | |
| pos = base // (a * b) | |
| s += -pos if (2 & b) != 0 else pos | |
| a *= x * x | |
| b += 2 | |
| return s | |
| start = time.time() | |
| pi = 4 * (4 * mpiarccot(5) - mpiarccot(239)) | |
| elapsed_time = time.time() - start | |
| print(pi) | |
| print(elapsed_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment