結果

問題 No.186 中華風 (Easy)
ユーザー kimiyukikimiyuki
提出日時 2016-12-27 17:52:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 686 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-05-08 20:28:08
合計ジャッジ時間 1,751 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 28 ms
10,880 KB
testcase_05 AC 28 ms
10,752 KB
testcase_06 AC 28 ms
10,880 KB
testcase_07 AC 28 ms
10,880 KB
testcase_08 AC 28 ms
10,752 KB
testcase_09 AC 28 ms
10,880 KB
testcase_10 AC 28 ms
10,880 KB
testcase_11 AC 28 ms
10,880 KB
testcase_12 AC 28 ms
10,880 KB
testcase_13 AC 28 ms
10,880 KB
testcase_14 AC 28 ms
10,752 KB
testcase_15 WA -
testcase_16 AC 28 ms
10,752 KB
testcase_17 AC 28 ms
10,880 KB
testcase_18 WA -
testcase_19 AC 29 ms
10,880 KB
testcase_20 AC 28 ms
10,752 KB
testcase_21 AC 28 ms
10,880 KB
testcase_22 AC 28 ms
10,752 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, 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