結果

問題 No.186 中華風 (Easy)
ユーザー kimiyukikimiyuki
提出日時 2016-12-27 17:53:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 10,732 KB
実行使用メモリ 8,104 KB
最終ジャッジ日時 2023-09-27 00:49:19
合計ジャッジ時間 1,446 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,020 KB
testcase_01 AC 16 ms
7,980 KB
testcase_02 AC 16 ms
7,960 KB
testcase_03 AC 15 ms
7,912 KB
testcase_04 AC 16 ms
7,920 KB
testcase_05 AC 17 ms
8,012 KB
testcase_06 AC 17 ms
7,924 KB
testcase_07 AC 16 ms
8,008 KB
testcase_08 AC 16 ms
7,964 KB
testcase_09 AC 17 ms
7,952 KB
testcase_10 AC 16 ms
7,924 KB
testcase_11 AC 16 ms
7,964 KB
testcase_12 AC 16 ms
7,936 KB
testcase_13 AC 17 ms
7,992 KB
testcase_14 AC 16 ms
8,104 KB
testcase_15 AC 16 ms
7,940 KB
testcase_16 AC 16 ms
7,920 KB
testcase_17 AC 16 ms
7,932 KB
testcase_18 AC 16 ms
8,008 KB
testcase_19 AC 16 ms
8,020 KB
testcase_20 AC 16 ms
7,948 KB
testcase_21 AC 16 ms
8,104 KB
testcase_22 AC 16 ms
7,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import math
lcm = lambda a, b: a * b // math.gcd(a, b)
def extgcd(a, b):
    if b == 0:
        return 1, 0
    else:
        na, nb = extgcd(b, a % b)
        return nb, na - a//b * nb
def modinv(a, n):
    return extgcd(a, n)[0] % n
def crt(eqn1, eqn2):
    x1, m1 = eqn1
    x2, m2 = eqn2
    d = math.gcd(m1, m2)
    x = x1 + (m1 // d) * (x2 - x1) * modinv(m1 // d, m2 // d)
    m = lcm(m1, m2)
    return x % m, m
eqn = [ tuple(map(int, input().split())) for _ in range(3) ]
ans, _ = crt(eqn[0], crt(eqn[1], eqn[2]))
if ans == 0:
    ans += lcm(eqn[0][1], lcm(eqn[1][1], eqn[2][1]))
for x, y in eqn:
    if ans % y != x:
        ans = -1
        break
print(ans)
0