結果
問題 |
No.3037 トグルトグルトグル!
|
ユーザー |
![]() |
提出日時 | 2025-06-12 16:52:04 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 999 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 82,216 KB |
実行使用メモリ | 67,580 KB |
最終ジャッジ日時 | 2025-06-12 16:53:11 |
合計ジャッジ時間 | 1,700 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 13 |
ソースコード
import sys def readints(): return list(map(int, sys.stdin.read().split())) def multiply(a, b, mod): return [ [(a[0][0]*b[0][0] + a[0][1]*b[1][0]) % mod, (a[0][0]*b[0][1] + a[0][1]*b[1][1]) % mod], [(a[1][0]*b[0][0] + a[1][1]*b[1][0]) % mod, (a[1][0]*b[0][1] + a[1][1]*b[1][1]) % mod] ] def matrix_pow(mat, power, mod): result = [[1, 0], [0, 1]] while power > 0: if power % 2 == 1: result = multiply(result, mat, mod) mat = multiply(mat, mat, mod) power //= 2 return result def compute_lucas(n, mod): if n == 0: return 2 % mod elif n == 1: return 1 % mod mat = [[1, 1], [1, 0]] mat_power = matrix_pow(mat, n-1, mod) return (mat_power[0][0] * 1 + mat_power[0][1] * 2) % mod def main(): data = readints() T = data[0] mod = 10**9 +7 for i in range(1, T+1): n = data[i] print(compute_lucas(n, mod)) if __name__ == "__main__": main()