結果

問題 No.53 悪の漸化式
ユーザー 👑 rin204rin204
提出日時 2022-07-04 15:45:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 476 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 71,740 KB
最終ジャッジ日時 2023-08-20 23:24:43
合計ジャッジ時間 2,924 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,228 KB
testcase_01 AC 74 ms
71,296 KB
testcase_02 AC 80 ms
71,468 KB
testcase_03 AC 75 ms
71,336 KB
testcase_04 AC 74 ms
71,480 KB
testcase_05 AC 75 ms
71,624 KB
testcase_06 AC 75 ms
71,352 KB
testcase_07 AC 74 ms
71,480 KB
testcase_08 AC 75 ms
71,276 KB
testcase_09 AC 71 ms
71,220 KB
testcase_10 AC 71 ms
71,740 KB
testcase_11 AC 70 ms
71,164 KB
testcase_12 AC 71 ms
71,392 KB
testcase_13 AC 81 ms
71,164 KB
testcase_14 AC 70 ms
71,624 KB
testcase_15 AC 71 ms
71,220 KB
testcase_16 AC 70 ms
71,452 KB
testcase_17 AC 71 ms
71,564 KB
testcase_18 AC 70 ms
71,572 KB
testcase_19 AC 72 ms
71,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

n = int(input())
if n == 0:
    print(4)
    exit()
nume = [0] * (n + 1)
deno = [0] * (n + 1)
nume[0] = 4
nume[1] = 3
deno[0] = 1
deno[1] = 1
for i in range(2, n + 1):
    n1 = nume[i - 1] * 19
    d1 = deno[i - 1]
    n2 = nume[i - 2] * 12
    d2 = deno[i - 2]
    d = d1 * d2 // gcd(d1, d2)
    n = n1 * d // d1 - n2 * d // d2
    d *= 4
    g = gcd(d, n)
    nume[i] = n // g
    deno[i] = d // g
ans = nume[-1] / deno[-1]
print("{:.20f}".format(ans))
0