結果

問題 No.2122 黄金比で擬似乱数生成
ユーザー とりゐとりゐ
提出日時 2022-11-04 22:16:32
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 816 ms / 2,000 ms
コード長 1,166 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 91,932 KB
最終ジャッジ日時 2023-09-26 02:49:01
合計ジャッジ時間 8,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
75,952 KB
testcase_01 AC 178 ms
79,248 KB
testcase_02 AC 79 ms
75,920 KB
testcase_03 AC 168 ms
79,060 KB
testcase_04 AC 148 ms
78,332 KB
testcase_05 AC 186 ms
78,904 KB
testcase_06 AC 80 ms
75,916 KB
testcase_07 AC 168 ms
79,240 KB
testcase_08 AC 176 ms
78,196 KB
testcase_09 AC 187 ms
78,100 KB
testcase_10 AC 187 ms
82,016 KB
testcase_11 AC 78 ms
76,160 KB
testcase_12 AC 184 ms
78,132 KB
testcase_13 AC 193 ms
79,004 KB
testcase_14 AC 203 ms
79,100 KB
testcase_15 AC 228 ms
79,596 KB
testcase_16 AC 384 ms
80,048 KB
testcase_17 AC 187 ms
78,312 KB
testcase_18 AC 78 ms
76,008 KB
testcase_19 AC 185 ms
78,408 KB
testcase_20 AC 79 ms
75,956 KB
testcase_21 AC 78 ms
76,012 KB
testcase_22 AC 809 ms
85,016 KB
testcase_23 AC 816 ms
84,880 KB
testcase_24 AC 740 ms
83,928 KB
testcase_25 AC 801 ms
91,932 KB
権限があれば一括ダウンロードができます

ソースコード

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