結果

問題 No.2122 黄金比で擬似乱数生成
ユーザー 👑 rin204rin204
提出日時 2022-11-04 23:28:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,680 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 80,476 KB
最終ジャッジ日時 2023-09-26 01:53:36
合計ジャッジ時間 9,109 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
76,960 KB
testcase_01 AC 200 ms
79,928 KB
testcase_02 AC 188 ms
78,732 KB
testcase_03 AC 200 ms
80,076 KB
testcase_04 AC 193 ms
79,176 KB
testcase_05 AC 219 ms
79,248 KB
testcase_06 AC 187 ms
78,732 KB
testcase_07 AC 201 ms
79,976 KB
testcase_08 AC 211 ms
79,076 KB
testcase_09 AC 208 ms
79,276 KB
testcase_10 AC 221 ms
78,536 KB
testcase_11 AC 158 ms
78,256 KB
testcase_12 AC 201 ms
78,816 KB
testcase_13 AC 208 ms
78,088 KB
testcase_14 AC 237 ms
79,232 KB
testcase_15 AC 268 ms
78,692 KB
testcase_16 AC 399 ms
79,164 KB
testcase_17 AC 204 ms
78,988 KB
testcase_18 AC 94 ms
77,016 KB
testcase_19 AC 206 ms
79,080 KB
testcase_20 AC 93 ms
76,872 KB
testcase_21 AC 92 ms
77,092 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 769 ms
79,024 KB
testcase_25 AC 808 ms
79,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
S = 0001 
の遷移 わかってない
"""

MOD = 10000

def add(x, y):
    if x[0] == 0:
        return y
    elif y[0] == 0:
        return x
    x = list(x)
    y = list(y)
    if x[1] > y[1]:
        x, y = y, x
    y[0] <<= y[1] - x[1]
    z0 = x[0] + y[0]
    z1 = x[1]
    return f(z0, z1)

def times(x, y):
    x = list(x)
    y = list(y)
    z0 = x[0] * y[0]
    z1 = x[1] + y[1]
    return f(z0, z1)

def matpow(A, B, w):
    l = len(A)
    while w:
        if w & 1:
            C = [(0, 0)] * l
            for i in range(l):
                for j in range(l):
                    C[i] = add(C[i], times(A[i][j], B[j]))
            B = C
        C = [[(0, 0)] * l for _ in range(l)]
        for i in range(l):
            for j in range(l):
                for k in range(l):
                    C[i][j] = add(C[i][j], times(A[i][k], A[k][j]))

        A = C
        w >>= 1
    return B

S = int(input())
m = int(input())
L = int(input())

nex = [0] * 10000

def f(x, r=0):
    if x == 0:
        return 0, 0
    while x % 2 == 0:
        r += 1
        x //= 2
    return x % MOD, r

for n in range(1, 10000):
    d = n * n + 4
    B = [f(2), f(0)]
    A = [[f(n, -1), f(d, -1)], [f(1, -1), f(n, -1)]]
    ret = matpow(A, B, m)
    
    ret = ret[1]
    nex[n] = ret[0] * pow(2, ret[1], MOD) % MOD
    if m % 2 == 1:
        nex[n] -= 1
        if nex[n] == -1:
            nex[n] = 9999


n = int(S)
se = set()
lst = []
while n not in se:
    se.add(n)
    lst.append(n)
    n = nex[n]

if len(lst) >= L + 1:
    ans = str(lst[L]).zfill(4)
    print(ans)
    exit()

ii = lst.index(n)
L -= ii
lst = lst[ii:]
L %= len(lst)
ans = str(lst[L]).zfill(4)
print(ans)
0