結果

問題 No.1595 The Final Digit
ユーザー hirayuu_yc
提出日時 2024-09-18 21:19:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 52,992 KB
最終ジャッジ日時 2024-09-18 21:19:24
合計ジャッジ時間 1,958 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

def bostan_mori(N,P,Q,MOD):
    while N>0:
        U=[0]*(len(P)+len(Q)-1)
        for i in range(len(P)):
            for j in range(len(Q)):
                if j%2==0:
                    U[i+j]+=P[i]*Q[j]
                else:
                    U[i+j]-=P[i]*Q[j]
                U[i+j]%=MOD
        P=U[N%2::2]
        V=[0]*(len(Q)*2-1)
        for i in range(len(Q)):
            for j in range(len(Q)):
                if j%2==0:
                    V[i+j]+=Q[i]*Q[j]
                else:
                    V[i+j]-=Q[i]*Q[j]
                V[i+j]%=MOD
        Q=V[0::2]
        N//=2
    return P[0]//Q[0]%MOD

p,q,r,K=map(int,input().split())
print(bostan_mori(K-1,[p,q-p,r-q-p],[1,-1,-1,-1],10))
0