結果

問題 No.186 中華風 (Easy)
ユーザー roarisroaris
提出日時 2022-11-11 13:50:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 570 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 71,824 KB
最終ジャッジ日時 2023-10-11 10:53:56
合計ジャッジ時間 3,079 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,500 KB
testcase_01 AC 70 ms
71,496 KB
testcase_02 AC 71 ms
71,652 KB
testcase_03 AC 70 ms
71,220 KB
testcase_04 AC 69 ms
71,652 KB
testcase_05 AC 70 ms
71,788 KB
testcase_06 AC 70 ms
71,456 KB
testcase_07 AC 70 ms
71,380 KB
testcase_08 AC 71 ms
71,404 KB
testcase_09 AC 72 ms
71,500 KB
testcase_10 AC 71 ms
71,656 KB
testcase_11 AC 70 ms
71,824 KB
testcase_12 AC 69 ms
71,276 KB
testcase_13 AC 70 ms
71,656 KB
testcase_14 AC 71 ms
71,496 KB
testcase_15 AC 71 ms
71,400 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 72 ms
71,404 KB
testcase_19 AC 71 ms
71,248 KB
testcase_20 AC 71 ms
71,404 KB
testcase_21 AC 70 ms
71,520 KB
testcase_22 AC 72 ms
71,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from math import gcd

def ext_gcd(a, b):
    if b==0:
        return 1, 0
    
    s, t = ext_gcd(b, a%b)
    return t, s-a//b*t

def crt(rs, ms):
    r, m = 0, 1
    
    for ri, mi in zip(rs, ms):
        p, q = ext_gcd(m, mi)
        g = gcd(m, mi)
        
        if (ri-r)%g!=0:
            return -1
        
        r += m*(ri-r)//g*p
        m *= mi//g
        r %= m
    
    return r

rs, ms = [], []

for _ in range(3):
    r, m = map(int, input().split())
    rs.append(r)
    ms.append(m)

ans = crt(rs, ms)
print(ans)
0