結果

問題 No.1648 Sum of Powers
ユーザー MitarushiMitarushi
提出日時 2021-07-29 15:34:57
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,022 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,732 KB
実行使用メモリ 100,016 KB
最終ジャッジ日時 2024-04-14 16:07:00
合計ジャッジ時間 10,088 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
99,632 KB
testcase_01 AC 69 ms
75,588 KB
testcase_02 AC 117 ms
99,376 KB
testcase_03 AC 114 ms
99,380 KB
testcase_04 AC 119 ms
99,764 KB
testcase_05 AC 119 ms
99,884 KB
testcase_06 AC 118 ms
99,508 KB
testcase_07 AC 115 ms
99,896 KB
testcase_08 AC 113 ms
99,884 KB
testcase_09 AC 119 ms
99,772 KB
testcase_10 AC 120 ms
99,780 KB
testcase_11 AC 121 ms
99,888 KB
testcase_12 AC 120 ms
99,668 KB
testcase_13 AC 112 ms
99,524 KB
testcase_14 AC 115 ms
99,396 KB
testcase_15 AC 117 ms
99,376 KB
testcase_16 AC 122 ms
99,880 KB
testcase_17 AC 120 ms
99,904 KB
testcase_18 AC 120 ms
99,652 KB
testcase_19 AC 119 ms
99,880 KB
testcase_20 AC 113 ms
100,016 KB
testcase_21 AC 120 ms
99,880 KB
testcase_22 AC 114 ms
99,648 KB
testcase_23 AC 114 ms
99,988 KB
testcase_24 AC 118 ms
99,628 KB
testcase_25 AC 120 ms
99,908 KB
testcase_26 AC 119 ms
99,680 KB
testcase_27 AC 115 ms
99,628 KB
testcase_28 AC 119 ms
99,648 KB
testcase_29 AC 119 ms
99,776 KB
testcase_30 AC 118 ms
99,656 KB
testcase_31 AC 141 ms
99,440 KB
testcase_32 AC 134 ms
99,656 KB
testcase_33 AC 139 ms
99,776 KB
testcase_34 AC 117 ms
99,712 KB
testcase_35 AC 119 ms
99,652 KB
testcase_36 AC 120 ms
99,648 KB
testcase_37 AC 132 ms
99,656 KB
testcase_38 AC 138 ms
99,392 KB
testcase_39 AC 115 ms
99,904 KB
testcase_40 AC 121 ms
99,884 KB
testcase_41 AC 135 ms
99,992 KB
testcase_42 AC 134 ms
99,504 KB
testcase_43 AC 123 ms
99,884 KB
testcase_44 AC 133 ms
99,392 KB
testcase_45 AC 136 ms
99,524 KB
testcase_46 AC 125 ms
99,396 KB
testcase_47 AC 115 ms
99,616 KB
testcase_48 AC 69 ms
75,616 KB
testcase_49 AC 114 ms
99,652 KB
testcase_50 AC 122 ms
99,636 KB
testcase_51 AC 68 ms
75,420 KB
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 132 ms
99,780 KB
testcase_56 AC 133 ms
99,628 KB
testcase_57 AC 70 ms
75,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def mul(l, r):
    la, lb, lc, ld = l
    ra, rb, rc, rd = r
    return (la*ra+lb*rc) % mod, (la*rb+lb*rd) % mod, (lc*ra+ld*rc) % mod, (lc*rb+ld*rd) % mod


def inv(x):
    a, b, c, d = x
    det = (a * d - b * c) % mod
    det_inv = pow(det, mod-2, mod)
    y = d, -b, -c, a
    return tuple(i * det_inv % mod for i in y)


def mat_pow(a, x):
    b = 1, 0, 0, 1
    while x:
        if x % 2 == 1:
            b = mul(b, a)
        a = mul(a, a)
        x //= 2
    return b


def bsgs(mat, a, b):
    k = 10 ** 5 + 100

    mat_k = mat_pow(mat, k)
    giant = {}
    x = a
    for i in range(k):
        giant[x] = i
        x = mul(mat_k, x)

    mat_inv = inv(mat)
    x = b
    for i in range(k):
        if x in giant:
            return giant[x] * k + i

        x = mul(mat_inv, x)

    return None


a, b, p, q = map(int, input().split())

if b != 0:
    mat = a, -b, 1, 0
else:
    mat = a, 0, 0, a

start = a ** 2 - 2 * b, 0, a, 0
finish = p, 0, q, 0
n = bsgs(mat, start, finish) + 2
print(n)
0