結果

問題 No.186 中華風 (Easy)
ユーザー 👑 timitimi
提出日時 2020-12-21 09:54:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 11,952 KB
実行使用メモリ 10,280 KB
最終ジャッジ日時 2023-10-21 11:29:34
合計ジャッジ時間 4,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 379 ms
10,280 KB
testcase_01 AC 60 ms
10,280 KB
testcase_02 AC 156 ms
10,280 KB
testcase_03 AC 30 ms
10,280 KB
testcase_04 AC 117 ms
10,280 KB
testcase_05 AC 121 ms
10,280 KB
testcase_06 AC 323 ms
10,280 KB
testcase_07 AC 86 ms
10,280 KB
testcase_08 AC 270 ms
10,280 KB
testcase_09 AC 264 ms
10,280 KB
testcase_10 AC 377 ms
10,280 KB
testcase_11 AC 363 ms
10,280 KB
testcase_12 AC 51 ms
10,280 KB
testcase_13 AC 177 ms
10,280 KB
testcase_14 AC 90 ms
10,280 KB
testcase_15 AC 54 ms
10,280 KB
testcase_16 AC 158 ms
10,280 KB
testcase_17 AC 39 ms
10,280 KB
testcase_18 AC 77 ms
10,280 KB
testcase_19 AC 29 ms
10,280 KB
testcase_20 AC 29 ms
10,280 KB
testcase_21 AC 29 ms
10,280 KB
testcase_22 AC 28 ms
10,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

a,b=map(int, input().split())
c,d=map(int, input().split())
e,f=map(int, input().split())
import math
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y
def chineseRem(b1, m1, b2, m2):
    # 中国剰余定理
    # x ≡ b1 (mod m1) ∧ x ≡ b2 (mod m2) <=> x ≡ r (mod m)
    # となる(r. m)を返す
    # 解無しのとき(0, -1)
    d, p, q = egcd(m1, m2)
    if (b2 - b1) % d != 0:
        return 0, -1
    m = m1 * (m2 // d)  # m = lcm(m1, m2)
    tmp = (b2-b1) // d * p % (m2 // d)
    r = (b1 + m1 * tmp) % m
    return r, m
x,y=chineseRem(a,b,c,d)
if x==0 and y==-1:
  print(-1)
  exit()
for i in range(10**6):
  d=i*y+x
  if d%f==e and d>0:
    print(d)
    exit()
print(-1)
0