結果

問題 No.344 ある無理数の累乗
ユーザー convexineqconvexineq
提出日時 2021-01-14 07:32:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 71,464 KB
最終ジャッジ日時 2023-08-15 12:24:22
合計ジャッジ時間 4,035 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
71,288 KB
testcase_01 AC 61 ms
71,084 KB
testcase_02 AC 60 ms
71,296 KB
testcase_03 AC 60 ms
71,232 KB
testcase_04 AC 60 ms
71,216 KB
testcase_05 AC 61 ms
71,228 KB
testcase_06 AC 61 ms
71,384 KB
testcase_07 AC 61 ms
71,244 KB
testcase_08 AC 61 ms
71,060 KB
testcase_09 AC 62 ms
71,452 KB
testcase_10 AC 61 ms
71,088 KB
testcase_11 AC 60 ms
71,404 KB
testcase_12 AC 63 ms
71,424 KB
testcase_13 AC 63 ms
71,016 KB
testcase_14 AC 62 ms
71,464 KB
testcase_15 AC 62 ms
71,280 KB
testcase_16 AC 60 ms
71,388 KB
testcase_17 AC 61 ms
71,400 KB
testcase_18 AC 62 ms
71,020 KB
testcase_19 AC 61 ms
71,436 KB
testcase_20 AC 61 ms
71,328 KB
testcase_21 AC 62 ms
71,192 KB
testcase_22 AC 61 ms
71,332 KB
testcase_23 AC 61 ms
71,184 KB
testcase_24 AC 61 ms
71,384 KB
testcase_25 AC 61 ms
71,084 KB
testcase_26 AC 61 ms
71,292 KB
testcase_27 AC 61 ms
71,244 KB
testcase_28 AC 62 ms
71,192 KB
testcase_29 AC 60 ms
71,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def matmul(A,B): # A,B: 行列
    res = [[0]*len(B[0]) for _ in [None]*len(A)]
    for i, resi in enumerate(res):
        for k, aik in enumerate(A[i]):
            for j,bkj in enumerate(B[k]):
                resi[j] += aik*bkj
                resi[j] %= MOD
    return res

def matpow(A,p): #A^p mod M
    if p%2:
        return matmul(A, matpow(A,p-1))
    elif p > 0:
        b = matpow(A,p//2)
        return matmul(b,b)
    else:
        return [[1 if i == j else 0 for j in range(len(A))] for i in range(len(A))]

MOD=1000
n = int(input())
A = matpow([[0,1],[2,2]],n)
c = A[0][0]*2 + A[0][1]*2
print((c+ (0 if n%2 else -1))%MOD)
0