結果

問題 No.2558 中国剰余定理
ユーザー loop0919loop0919
提出日時 2023-09-21 17:51:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 354 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 71,592 KB
最終ジャッジ日時 2023-09-21 17:51:55
合計ジャッジ時間 5,094 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,380 KB
testcase_01 AC 77 ms
71,380 KB
testcase_02 AC 74 ms
71,332 KB
testcase_03 AC 75 ms
71,080 KB
testcase_04 AC 73 ms
71,256 KB
testcase_05 AC 73 ms
71,568 KB
testcase_06 AC 74 ms
71,308 KB
testcase_07 AC 73 ms
71,580 KB
testcase_08 AC 74 ms
71,324 KB
testcase_09 AC 75 ms
71,412 KB
testcase_10 AC 74 ms
71,076 KB
testcase_11 AC 74 ms
71,500 KB
testcase_12 AC 73 ms
71,480 KB
testcase_13 AC 74 ms
71,444 KB
testcase_14 AC 75 ms
71,572 KB
testcase_15 AC 73 ms
71,264 KB
testcase_16 AC 73 ms
71,436 KB
testcase_17 AC 73 ms
71,532 KB
testcase_18 AC 76 ms
71,060 KB
testcase_19 AC 74 ms
71,380 KB
testcase_20 AC 73 ms
71,364 KB
testcase_21 AC 75 ms
71,464 KB
testcase_22 AC 75 ms
71,436 KB
testcase_23 AC 73 ms
71,260 KB
testcase_24 AC 74 ms
71,372 KB
testcase_25 AC 73 ms
71,228 KB
testcase_26 AC 73 ms
71,356 KB
testcase_27 AC 74 ms
71,220 KB
testcase_28 AC 75 ms
71,224 KB
testcase_29 AC 73 ms
71,384 KB
testcase_30 AC 77 ms
71,592 KB
testcase_31 AC 76 ms
71,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# aとbの最大公約数gcdと、a*x - b*y = 1 の特殊解x, y を返す
def extended_gcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        gcd, x, y = extended_gcd(b % a, a)
        return gcd, y - (b // a) * x, x


A, B, a, b = map(int, input().split())
gcd, x, y = extended_gcd(A, B)

ans = ((A * x) * (b - a) + a) % (A * B)
print(ans)
0