結果
| 問題 |
No.313 π
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-11 22:45:21 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,081 bytes |
| コンパイル時間 | 203 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 14,112 KB |
| 最終ジャッジ日時 | 2024-06-11 22:45:55 |
| 合計ジャッジ時間 | 24,262 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | WA * 32 |
ソースコード
# 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)
print(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()