結果
| 問題 |
No.613 Solitude by the window
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-13 00:07:23 |
| 言語 | Python2 (2.7.18) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 884 bytes |
| コンパイル時間 | 128 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-14 06:56:09 |
| 合計ジャッジ時間 | 1,186 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 21 |
ソースコード
#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
n, mod = map(int, raw_input().split())
assert n == 1
if n > 100:
p = pow(2, n, mod-1) + mod - 1
else:
p = 2 ** n
def matmul(A, B):
p, q = len(A[0]), len(B)
if p != q:
raise ValueError('len(A[0])={} len(B)={}'.format(p, q))
rows, cols, times = len(A), len(B[0]), len(A[0])
res = [[0] * cols for _ in xrange(rows)]
for r in xrange(rows):
for c in xrange(cols):
res[r][c] = sum(A[r][i]*B[i][c] % mod for i in xrange(times)) % mod
return res
def matpow(A, n):
m = len(A)
res = [[int(i==j) for j in xrange(m)] for i in xrange(m)]
while n > 0:
if n & 1:
res = matmul(res, A)
A = matmul(A, A)
n >>= 1
return res
A = [[2, 3], [1, 2]]
B = matpow(A, 2**n)
C = [[1], [0]]
D = matmul(B, C)
res = 2 * D[0][0]
res %= mod
print res