結果
問題 | No.2122 黄金比で擬似乱数生成 |
ユーザー | 👑 rin204 |
提出日時 | 2022-11-05 00:16:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 705 ms / 2,000 ms |
コード長 | 2,383 bytes |
コンパイル時間 | 528 ms |
コンパイル使用メモリ | 82,420 KB |
実行使用メモリ | 81,924 KB |
最終ジャッジ日時 | 2024-07-18 22:13:12 |
合計ジャッジ時間 | 7,488 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
76,160 KB |
testcase_01 | AC | 159 ms
81,260 KB |
testcase_02 | AC | 141 ms
77,468 KB |
testcase_03 | AC | 152 ms
81,308 KB |
testcase_04 | AC | 156 ms
81,216 KB |
testcase_05 | AC | 180 ms
78,244 KB |
testcase_06 | AC | 141 ms
77,336 KB |
testcase_07 | AC | 158 ms
81,516 KB |
testcase_08 | AC | 162 ms
77,572 KB |
testcase_09 | AC | 161 ms
77,232 KB |
testcase_10 | AC | 182 ms
77,364 KB |
testcase_11 | AC | 124 ms
77,404 KB |
testcase_12 | AC | 173 ms
77,548 KB |
testcase_13 | AC | 177 ms
77,280 KB |
testcase_14 | AC | 189 ms
78,212 KB |
testcase_15 | AC | 222 ms
77,676 KB |
testcase_16 | AC | 331 ms
81,924 KB |
testcase_17 | AC | 168 ms
77,668 KB |
testcase_18 | AC | 75 ms
75,904 KB |
testcase_19 | AC | 175 ms
77,676 KB |
testcase_20 | AC | 70 ms
76,160 KB |
testcase_21 | AC | 73 ms
76,160 KB |
testcase_22 | AC | 695 ms
78,856 KB |
testcase_23 | AC | 705 ms
78,176 KB |
testcase_24 | AC | 641 ms
78,128 KB |
testcase_25 | AC | 653 ms
78,936 KB |
ソースコード
MOD = 100000000 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): if x[0] == 0 or y[0] == 0: return (0, 0) 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 def matpow_normal(A, B, w): l = len(A) while w: if w & 1: C = [0] * l for i in range(l): for j in range(l): C[i] += A[i][j] * B[j] C[i] %= MOD B = C C = [[0] * l for _ in range(l)] for i in range(l): for j in range(l): for k in range(l): C[i][j] += A[i][k] * A[k][j] C[i][j] %= MOD 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(2, 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], 10000) % 10000 if m % 2 == 1: nex[n] -= 1 if nex[n] == -1: nex[n] = 9999 A = [[1, 1], [1, 0]] B = [0, 1] nex[1] = matpow_normal(A, B, m)[0] % 10000 if m % 2 == 1 and m <= 35: nex[1] -= 1 if nex[1] == -1: nex[1] = 9999 n = int(S) doubling = [[-1] * 10000 for _ in range(60)] for i in range(10000): doubling[0][i] = nex[i] for i in range(1, 60): for j in range(10000): doubling[i][j] = doubling[i - 1][doubling[i - 1][j]] for i in range(60): if L >> i & 1: n = doubling[i][n] ans = str(n).zfill(4) print(ans)