結果

問題 No.313 π
ユーザー ir5ir5
提出日時 2024-06-11 22:45:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,081 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 14,112 KB
最終ジャッジ日時 2024-06-11 22:45:55
合計ジャッジ時間 24,262 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
    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()
0