結果

問題 No.186 中華風 (Easy)
ユーザー brthyyjpbrthyyjp
提出日時 2020-04-26 20:29:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 881 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 72,720 KB
最終ジャッジ日時 2023-09-27 00:59:23
合計ジャッジ時間 4,392 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
72,364 KB
testcase_01 AC 112 ms
72,332 KB
testcase_02 AC 113 ms
72,328 KB
testcase_03 AC 111 ms
72,180 KB
testcase_04 AC 112 ms
72,324 KB
testcase_05 AC 115 ms
72,524 KB
testcase_06 AC 114 ms
72,220 KB
testcase_07 AC 112 ms
72,456 KB
testcase_08 AC 113 ms
72,184 KB
testcase_09 AC 113 ms
72,456 KB
testcase_10 AC 115 ms
72,516 KB
testcase_11 AC 114 ms
72,340 KB
testcase_12 AC 113 ms
72,392 KB
testcase_13 AC 113 ms
72,332 KB
testcase_14 AC 111 ms
72,220 KB
testcase_15 AC 113 ms
72,492 KB
testcase_16 AC 113 ms
72,604 KB
testcase_17 AC 110 ms
72,720 KB
testcase_18 AC 112 ms
72,692 KB
testcase_19 AC 112 ms
72,480 KB
testcase_20 AC 113 ms
72,552 KB
testcase_21 AC 113 ms
72,404 KB
testcase_22 AC 113 ms
72,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a, b):
    if b == 0:
        return 1, 0, a
    q, r = divmod(a, b)
    x, y, d = extgcd(b, r)
    s, t = y, x-q*y
    return s, t, d

def mod(a, m):
    return (a%m + m)%m;

def CRT_list(b, m):
    #b: list
    #m: lsit
    r, M = 0, 1
    for i in range(len(b)):
        p, q, d = extgcd(M, m[i])
        if (b[i]-r)%d != 0:
            return 0, -1
        temp = (b[i]-r)//d * p % (m[i]//d)
        r += M * temp
        M *= m[i]//d
    return mod(r, M), M

import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

X = []
Y = []
for i in range(3):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

if X[0] == 0 and X[1] == 0 and X[2] == 0:
    print(lcm_list(Y))
    exit()

r, M = CRT_list(X, Y)
if M == -1:
    print(-1)
else:
    print(r)
0