結果
| 問題 | 
                            No.3226 2×2行列累乗
                             | 
                    
| コンテスト | |
| ユーザー | 
                             timi
                         | 
                    
| 提出日時 | 2025-08-08 21:49:40 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 804 bytes | 
| コンパイル時間 | 182 ms | 
| コンパイル使用メモリ | 82,084 KB | 
| 実行使用メモリ | 54,348 KB | 
| 最終ジャッジ日時 | 2025-08-08 21:49:44 | 
| 合計ジャッジ時間 | 2,329 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 WA * 2 | 
ソースコード
a,b=map(int, input().split())
c,d=map(int, input().split())
s,t=map(int, input().split())
N,K=map(int, input().split())
mod=K
if N==0:
  print(s,t)
  exit()
def matmul(A, B):
    Ah, Bh, Bw = len(A), len(B), len(B[0])
    C = [[0 for _ in range(Bw)] for _ in range(Ah)]
    for i in range(Ah):
        for j in range(Bw):
            for k in range(Bh):
                C[i][j] += A[i][k] * B[k][j] % mod
                C[i][j] %= mod
    return C
# Mのk乗を効率的に計算する
def doubling(M, k):
    k -= 1
    Mc = M.copy()
    while k > 0:
        if k & 1 == 1:
            Mc = matmul(Mc, M)
        M = matmul(M, M) # Mの(2のi乗)の乗 を計算する
        k >>= 1
    return Mc 
 
M = [[a, b], [c, d]]
F = [[s], [t]]
Mn = doubling(M, N)
G = matmul(Mn, F)
print(G[0][0],G[1][0])
            
            
            
        
            
timi