結果

問題 No.53 悪の漸化式
ユーザー lloyzlloyz
提出日時 2022-08-10 01:51:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 537 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 11,840 KB
実行使用メモリ 10,192 KB
最終ジャッジ日時 2023-10-20 11:16:29
合計ジャッジ時間 2,430 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,192 KB
testcase_01 AC 29 ms
10,192 KB
testcase_02 AC 29 ms
10,192 KB
testcase_03 AC 30 ms
10,192 KB
testcase_04 AC 30 ms
10,192 KB
testcase_05 AC 29 ms
10,192 KB
testcase_06 AC 28 ms
10,192 KB
testcase_07 AC 29 ms
10,192 KB
testcase_08 AC 30 ms
10,192 KB
testcase_09 AC 29 ms
10,192 KB
testcase_10 AC 29 ms
10,192 KB
testcase_11 AC 30 ms
10,192 KB
testcase_12 AC 29 ms
10,192 KB
testcase_13 AC 29 ms
10,192 KB
testcase_14 AC 29 ms
10,192 KB
testcase_15 AC 29 ms
10,192 KB
testcase_16 AC 29 ms
10,192 KB
testcase_17 AC 29 ms
10,192 KB
testcase_18 AC 29 ms
10,192 KB
testcase_19 AC 30 ms
10,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

n = int(input())

if n == 0:
    print(4.0)
    exit()
if n == 1:
    print(3.0)
    exit()

nume = [0 for _ in range(n + 1)]
deno = [0 for _ in range(n + 1)]
nume[0] = 4
deno[0] = 1
nume[1] = 3
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]
    lcm = d1 * d2 // gcd(d1, d2)
    nu = n1 * lcm // d1 - n2 * lcm // d2
    lcm *= 4
    g = gcd(nu, lcm)
    nume[i] = nu // g
    deno[i] = lcm // g
print(f"{nume[n] / deno[n]:.20f}")
0