結果

問題 No.2117 中国剰余定理入門
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-11-13 20:34:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 1,396 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 71,576 KB
最終ジャッジ日時 2023-10-13 04:32:39
合計ジャッジ時間 3,153 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,456 KB
testcase_01 AC 73 ms
71,164 KB
testcase_02 AC 73 ms
71,496 KB
testcase_03 AC 72 ms
71,372 KB
testcase_04 AC 73 ms
71,512 KB
testcase_05 AC 75 ms
71,212 KB
testcase_06 AC 71 ms
71,408 KB
testcase_07 AC 72 ms
71,164 KB
testcase_08 AC 71 ms
71,548 KB
testcase_09 AC 71 ms
71,548 KB
testcase_10 AC 73 ms
71,160 KB
testcase_11 AC 73 ms
71,380 KB
testcase_12 AC 72 ms
71,216 KB
testcase_13 AC 72 ms
71,304 KB
testcase_14 AC 72 ms
71,456 KB
testcase_15 AC 77 ms
71,032 KB
testcase_16 AC 72 ms
71,028 KB
testcase_17 AC 72 ms
71,576 KB
testcase_18 AC 73 ms
71,372 KB
testcase_19 AC 74 ms
71,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
def Chinese_Surplus_Theorem(b1,b2,m1,m2):
    def Euclidean_Algorithm(a,b,d):
        a,b = max(a,b),min(a,b)
        if a == d and b == 0:
            return 1,0
        div,mod = divmod(a,b)
        nx,ny = Euclidean_Algorithm(b,mod,d)
        res = (ny,nx - div*ny)
        return res
    d = math.gcd(m1,m2)
    if m1 < m2:
        m1,m2 = m2,m1
        b1,b2 = b2,b1
    if b1 % d != b2 % d:return 0,0
    p,q = Euclidean_Algorithm(m1,m2,d)
    s = (b2-b1)//d
    return (b1 + s*m1*p) % (m1*m2//d) ,m1*m2//d

b0,c0 = map(int,input().split())
b1,c1 = map(int,input().split())
# c0 %= b0
# c1 %= b1
x,y = Chinese_Surplus_Theorem(c0,c1,b0,b1)
if x == y == 0:
    print("NaN")
else:
    print(x)
0