結果
| 問題 |
No.187 中華風 (Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-08 09:38:08 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 826 bytes |
| コンパイル時間 | 87 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-09-16 07:28:08 |
| 合計ジャッジ時間 | 2,730 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 WA * 2 |
ソースコード
# -*- coding: UTF-8 -*-
def exgcd(a: int, b: int) -> (int, int, int):
# 返回 (gcd(a,b), x, y) 满足 gcd(a,b)=ax+by
x1, x2, x3, x4 = 1, 0, 0, 1
while b != 0:
q = a // b
x1, x2, x3, x4, a, b = x3, x4, x1 - x3 * q, x2 - x4 * q, b, a - b * q
return a, x1, x2
def gcrt2(a: int, m1: int, b: int, m2: int) -> (int, int):
d, x, y = exgcd(m1, m2)
bma = b - a
if bma % d != 0:
return -1, -1
t, y = m2 // d, bma // d
res = x * y % t
if res < 0:
res += t
return res * m1 + a, m1 * t
if __name__ == '__main__':
n = int(input())
ans, m0 = 0, 1
for _ in range(0, n):
c, d = (int(i) for i in input().split(' '))
ans, m0 = gcrt2(ans, m0, c, d)
if ans == -1:
break
print(-1 if ans == -1 else ans % 1000000007)