結果

問題 No.344 ある無理数の累乗
ユーザー 👑 rin204rin204
提出日時 2022-11-09 21:30:08
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 651 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 71,536 KB
最終ジャッジ日時 2023-09-30 08:35:03
合計ジャッジ時間 4,080 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,440 KB
testcase_01 AC 75 ms
71,268 KB
testcase_02 AC 75 ms
71,064 KB
testcase_03 AC 77 ms
71,212 KB
testcase_04 AC 75 ms
71,416 KB
testcase_05 AC 76 ms
71,504 KB
testcase_06 AC 77 ms
71,532 KB
testcase_07 AC 74 ms
71,388 KB
testcase_08 AC 75 ms
71,344 KB
testcase_09 AC 74 ms
71,224 KB
testcase_10 AC 75 ms
71,340 KB
testcase_11 AC 76 ms
71,376 KB
testcase_12 AC 74 ms
71,292 KB
testcase_13 AC 77 ms
71,404 KB
testcase_14 AC 78 ms
71,288 KB
testcase_15 AC 77 ms
71,212 KB
testcase_16 AC 74 ms
71,420 KB
testcase_17 AC 74 ms
71,336 KB
testcase_18 AC 76 ms
71,152 KB
testcase_19 AC 75 ms
71,296 KB
testcase_20 AC 75 ms
71,396 KB
testcase_21 AC 76 ms
71,344 KB
testcase_22 AC 77 ms
71,476 KB
testcase_23 AC 79 ms
71,348 KB
testcase_24 AC 76 ms
71,180 KB
testcase_25 AC 77 ms
71,204 KB
testcase_26 AC 75 ms
71,536 KB
testcase_27 AC 76 ms
71,416 KB
testcase_28 AC 74 ms
71,464 KB
testcase_29 AC 75 ms
71,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 1000

def matpow(A, B, w):
    l = len(A)
    while w:
        if w & 1:
            C = [0] * l
            for i in range(l):
                for j in range(l):
                    C[i] += A[i][j] * B[j]
                    C[i] %= MOD
            B = C
        C = [[0] * l for _ in range(l)]
        for i in range(l):
            for j in range(l):
                for k in range(l):
                    C[i][j] += A[i][k] * A[k][j]
                    C[i][j] %= MOD
        A = C
        w >>= 1
    return B

n = int(input())
A = [[1, 3], [1, 1]]
B = [1, 0]
ans = matpow(A, B, n)[0] * 2
if n % 2 == 0:
    ans -= 1
ans %= MOD
print(ans)
0