結果

問題 No.2122 黄金比で擬似乱数生成
ユーザー とりゐとりゐ
提出日時 2022-11-04 22:16:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 670 ms / 2,000 ms
コード長 1,166 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,160 KB
実行使用メモリ 85,316 KB
最終ジャッジ日時 2024-07-18 22:07:17
合計ジャッジ時間 6,197 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

def matmul(A,B,mod):
    res = [[0]*len(B[0]) for _ in [None]*len(A)]
    for i, resi in enumerate(res):
        for k, aik in enumerate(A[i]):
            for j,bkj in enumerate(B[k]):
                resi[j] += aik*bkj
                resi[j] %= mod
    return res

def matpow(A,p,mod):
    if p%2:
        return matmul(A, matpow(A,p-1,mod),mod)
    elif p > 0:
        b = matpow(A,p//2,mod)
        return matmul(b,b,mod)
    else:
        return [[int(i==j) for j in range(len(A))] for i in range(len(A))]

mod=10000
def calc(x,m):
  if x==0:
    return 0
  if m==0:
    return 0
  mat=[[x,1],
       [1,0]]
  if m==1:
    return 0
  if m==2:
    return x
  matp=matpow(mat,m-2,mod)
  res=matmul(matp,[[x],[1]],mod)
  ans=res[0][0]
  if m%2==1:
    ans-=1
  return ans%mod

s=int(input())
m=int(input())
bit=int(input())

n=10000
nxt=[0]*10000
for i in range(n):
  nxt[i]=calc(i,m)

table=[]
table.append(nxt)

for i in range(60):
  nxt=[0]*n
  for j in range(n):
    nxt[j]=table[-1][table[-1][j]]
  table.append(nxt)

now=s
for i in range(60):
  if (bit>>i)&1:
    now=table[i][now]

ans=str(now)
if now==0:
  print('0'*4)
else:
  print('0'*(4-len(ans))+ans)
0