結果
問題 | No.1648 Sum of Powers |
ユーザー | tamato |
提出日時 | 2021-08-13 23:14:16 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,148 bytes |
コンパイル時間 | 235 ms |
コンパイル使用メモリ | 82,648 KB |
実行使用メモリ | 259,284 KB |
最終ジャッジ日時 | 2024-10-03 22:58:53 |
合計ジャッジ時間 | 27,363 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,502 ms
258,252 KB |
testcase_01 | AC | 39 ms
52,352 KB |
testcase_02 | AC | 48 ms
63,488 KB |
testcase_03 | AC | 48 ms
63,744 KB |
testcase_04 | AC | 50 ms
63,616 KB |
testcase_05 | AC | 50 ms
63,744 KB |
testcase_06 | AC | 48 ms
63,744 KB |
testcase_07 | AC | 49 ms
63,744 KB |
testcase_08 | AC | 49 ms
63,360 KB |
testcase_09 | AC | 49 ms
63,744 KB |
testcase_10 | AC | 48 ms
63,616 KB |
testcase_11 | AC | 46 ms
63,232 KB |
testcase_12 | AC | 49 ms
63,488 KB |
testcase_13 | AC | 49 ms
63,744 KB |
testcase_14 | AC | 47 ms
63,232 KB |
testcase_15 | AC | 48 ms
63,744 KB |
testcase_16 | AC | 49 ms
63,616 KB |
testcase_17 | AC | 50 ms
63,744 KB |
testcase_18 | AC | 47 ms
62,976 KB |
testcase_19 | AC | 50 ms
63,872 KB |
testcase_20 | AC | 47 ms
63,004 KB |
testcase_21 | AC | 49 ms
63,616 KB |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
testcase_44 | TLE | - |
testcase_45 | TLE | - |
testcase_46 | TLE | - |
testcase_47 | AC | 47 ms
64,544 KB |
testcase_48 | AC | 38 ms
53,560 KB |
testcase_49 | AC | 49 ms
64,664 KB |
testcase_50 | AC | 49 ms
65,648 KB |
testcase_51 | AC | 44 ms
60,976 KB |
testcase_52 | AC | 39 ms
54,208 KB |
testcase_53 | AC | 39 ms
54,236 KB |
testcase_54 | AC | 38 ms
54,512 KB |
testcase_55 | TLE | - |
testcase_56 | TLE | - |
testcase_57 | AC | 41 ms
59,156 KB |
ソースコード
mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.readline def matmul(A, B): C = [[0] * len(B[0]) for _ in range(len(A))] for i in range(len(A)): for k in range(len(B)): for j in range(len(B[0])): C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod return C def matpow(A, p): n = len(A) B = [[0] * n for _ in range(n)] for i in range(n): B[i][i] = 1 while p > 0: if p & 1: B = matmul(B, A) A = matmul(A, A) p >>= 1 return B # x**k == y % mod # O(mod**0.5) def DiscreteLog(x, y, mod): m = int(mod ** 0.5) + 1 dic = {1: 0} # baby-step xi = 1 for i in range(1, m + 1): xi = (xi * x) % mod dic[xi] = i if y in dic: return dic[y] # giant-step r = pow(xi, mod - 2, mod) for a in range(1, m + 1): y = (y * r) % mod if y in dic: return a * m + dic[y] return -1 A, B, P, Q = map(int, input().split()) if B == 0: ans = DiscreteLog(A, P, mod) if 2 <= ans <= 10 ** 18: print(ans) else: print(ans + mod - 1) exit() if (A * A - 2 * B)%mod == P and A == Q: print(2) exit() M = [[A, -B], [1, 0]] B_inv = pow(B, mod-2, mod) M_inv = [[0, 1], [(-B_inv)%mod, (A * B_inv)%mod]] M_pow = {} M_cur = [[1, 0], [0, 1]] initial_vec = [[A], [2]] for i in range(1, 10 ** 6): M_cur = matmul(M_cur, M) U = matmul(M_cur, initial_vec) U_hash = U[0][0] * mod + U[1][0] M_pow[U_hash] = i M_inv_cur = [[1, 0], [0, 1]] last_vec = [[P], [Q]] for i in range(1, 10 ** 6): M_inv_cur = matmul(M_inv_cur, M_inv) V = matmul(M_inv_cur, last_vec) V_hash = V[0][0] * mod + V[1][0] if V_hash in M_pow: j = M_pow[V_hash] print(i + j + 1) exit() if __name__ == '__main__': main()