結果

問題 No.1275 綺麗な式
ユーザー tanon710
提出日時 2020-10-30 23:09:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 571 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 54,728 KB
最終ジャッジ日時 2024-07-22 02:49:59
合計ジャッジ時間 3,895 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7

def prod(a,b):
    ret=[[0,0],[0,0]]
    for i in range(2):
        for j in range(2):
            for k in range(2):
                ret[i][j]+=a[i][k]*b[k][j]
            ret[i][j]%=mod
    return ret

a,b=map(int,input().split())
n=int(input())
a1=2*a
a2=2*(a**2+b)
if n==0:
    print(2)
elif n==1:
    print(a1)
elif n==2:
    print(a2)
else:
    n-=2
    mat=[[1,0],[0,1]]
    coef=[[2*a,-(a**2-b)],[1,0]]
    for i in range(60):
        if n&(2**i):
            mat=prod(mat,coef)
        coef=prod(coef,coef)
    print((mat[0][0]*a2+mat[0][1]*a1)%mod)
0