結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
99,648 KB
testcase_01 AC 68 ms
75,260 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
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 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 RE -
testcase_48 AC 68 ms
75,624 KB
testcase_49 RE -
testcase_50 RE -
testcase_51 AC 67 ms
75,292 KB
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 68 ms
75,524 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] + 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