結果

問題 No.186 中華風 (Easy)
ユーザー 👑 timitimi
提出日時 2020-12-21 09:53:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 11,948 KB
実行使用メモリ 10,288 KB
最終ジャッジ日時 2023-10-21 11:29:29
合計ジャッジ時間 4,595 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 327 ms
10,288 KB
testcase_01 AC 58 ms
10,288 KB
testcase_02 AC 150 ms
10,288 KB
testcase_03 AC 27 ms
10,288 KB
testcase_04 AC 111 ms
10,288 KB
testcase_05 AC 114 ms
10,288 KB
testcase_06 AC 307 ms
10,288 KB
testcase_07 AC 76 ms
10,288 KB
testcase_08 AC 247 ms
10,288 KB
testcase_09 AC 241 ms
10,288 KB
testcase_10 AC 347 ms
10,288 KB
testcase_11 AC 353 ms
10,288 KB
testcase_12 AC 49 ms
10,288 KB
testcase_13 AC 173 ms
10,288 KB
testcase_14 AC 82 ms
10,288 KB
testcase_15 AC 49 ms
10,288 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 76 ms
10,288 KB
testcase_19 AC 26 ms
10,288 KB
testcase_20 AC 27 ms
10,288 KB
testcase_21 AC 26 ms
10,288 KB
testcase_22 AC 26 ms
10,288 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+1):
  d=i*y+x
  if d%f==e:
    print(d)
    exit()
print(-1)
0