結果

問題 No.1810 RGB Biscuits
ユーザー aaaaaaaaaa2230
提出日時 2022-01-14 22:59:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 77,840 KB
最終ジャッジ日時 2024-11-20 13:35:52
合計ジャッジ時間 3,322 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

a,b = map(int,input().split())
mod = 10**9+7

def calc(x,y):
        ans = [[0]*3 for i in range(3)]
        for i in range(3):
            for j in range(3):
                for k in range(3):
                    ans[i][j] += x[i][k]*y[k][j]
                    ans[i][j] %= mod
        return ans

def solve():
    t = int(input())

    base = [[0]*3 for i in range(3)]
    for i in range(3):
        base[i][i] = 1
    A = [[1,0,0],[0,1,0],[a,b,0]]
    B = [[0,0,1],[1,0,0],[0,0,0]]

    C = calc(B,A)

    now = t//2
    while now:
        if now & 1:
            base = calc(C,base)
        C = calc(C,C)
        now //= 2

    if t & 1:
        base = calc(A,base)

    ans = 0
    for i in range(3):
        for j in range(2):
            ans += base[i][j]
    return ans%mod
n = int(input())
for i in range(n):
    print(solve())
0