結果

問題 No.1648 Sum of Powers
ユーザー MitarushiMitarushi
提出日時 2021-07-29 15:33:34
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 980 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 100,176 KB
最終ジャッジ日時 2024-04-14 16:06:08
合計ジャッジ時間 12,761 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
99,644 KB
testcase_01 AC 68 ms
75,636 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 114 ms
99,520 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 113 ms
99,908 KB
testcase_23 AC 113 ms
99,920 KB
testcase_24 AC 120 ms
99,656 KB
testcase_25 AC 117 ms
99,528 KB
testcase_26 AC 120 ms
99,896 KB
testcase_27 AC 115 ms
99,764 KB
testcase_28 AC 118 ms
99,896 KB
testcase_29 AC 117 ms
99,788 KB
testcase_30 AC 117 ms
99,664 KB
testcase_31 AC 141 ms
99,644 KB
testcase_32 AC 135 ms
99,660 KB
testcase_33 AC 141 ms
99,788 KB
testcase_34 AC 119 ms
99,752 KB
testcase_35 AC 117 ms
99,912 KB
testcase_36 AC 120 ms
99,660 KB
testcase_37 AC 135 ms
99,648 KB
testcase_38 AC 138 ms
99,636 KB
testcase_39 AC 113 ms
99,532 KB
testcase_40 AC 119 ms
99,664 KB
testcase_41 AC 136 ms
99,780 KB
testcase_42 AC 132 ms
99,672 KB
testcase_43 AC 123 ms
99,396 KB
testcase_44 AC 133 ms
99,396 KB
testcase_45 AC 132 ms
99,380 KB
testcase_46 AC 122 ms
99,664 KB
testcase_47 RE -
testcase_48 AC 69 ms
75,528 KB
testcase_49 RE -
testcase_50 RE -
testcase_51 AC 69 ms
75,288 KB
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 133 ms
99,532 KB
testcase_56 AC 134 ms
99,772 KB
testcase_57 AC 72 ms
75,508 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())

mat = a, -b, 1, 0

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