結果

問題 No.313 π
ユーザー ir5
提出日時 2024-06-11 22:45:58
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 685 ms / 5,000 ms
コード長 2,067 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 13,976 KB
最終ジャッジ日時 2024-06-11 22:46:25
合計ジャッジ時間 25,361 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

# https://qiita.com/ykoba1994/items/44dd55c53663cec08398
from decimal import Decimal, getcontext, MAX_EMAX, MIN_EMIN
import math, time
from sys import argv
getcontext().Emax = MAX_EMAX #
getcontext().Emin = MIN_EMIN #
# cdecimal
def confirm_cdecimal():
a = True
try:
import _decimal
except ModuleNotFoundError:
a = False
return a
#
def my_sqrt(x):
x2 = Decimal(x)
if getcontext().prec <= 128:
return x2.sqrt()
else:
prec_orig = getcontext().prec
t = (prec_orig * 53) // 100
prec_list = []
while t > 128:
prec_list.append(t)
t = t // 2
prec_list.reverse()
getcontext().prec = 128
a = 1 / x2.sqrt()
for i in prec_list:
getcontext().prec = i + 10
a = a + (a * (Decimal(1) - x2 * (a * a)) / Decimal(2))
getcontext().prec = prec_orig
a = a + (a * (Decimal(1) - x2 * (a * a)) / Decimal(2))
return x2 * a
# Binary Splitting
def computePQT(a, b):
if b == a + 1:
p_int = (1 - 2*b) * (6*b - 5) * (6*b - 1)
q_int = (b**3) * 10939058860032000
t_int = p_int * (13591409 + 545140134*b)
return [Decimal(p_int), Decimal(q_int), Decimal(t_int)]
else:
m = (a + b) // 2
[pam, qam, tam] = computePQT(a, m)
[pmb, qmb, tmb] = computePQT(m, b)
p = pam * pmb
q = qam * qmb
t = tam * qmb + pam * tmb
return [p, q, t]
#
def chudnovsky_pi(n):
getcontext().prec = n
terms = math.ceil(n / 14.181647462) + 10
[_, q, t] = computePQT(0, terms)
num = q * Decimal(426880) * my_sqrt(10005)
den = t + q * Decimal(13591409)
return num / den
def main():
prec = 2 * 10 ** 5 + 10
pi = chudnovsky_pi(prec)
pi = str(pi)
s = input()
for i in range(len(s)):
if pi[i] != s[i]:
print(f"{s[i]} {pi[i]}")
break
if __name__ == "__main__":
main()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0