結果
問題 |
No.186 中華風 (Easy)
|
ユーザー |
|
提出日時 | 2023-06-04 20:35:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 836 bytes |
コンパイル時間 | 514 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 54,528 KB |
最終ジャッジ日時 | 2024-12-29 03:48:26 |
合計ジャッジ時間 | 2,635 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
from math import gcd from bisect import bisect_left, bisect_right from heapq import heappop, heappush from collections import defaultdict, deque, Counter import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline def extgcd(a, b): if b == 0: return 1, 0, a q, r = a//b, a % b x, y, d = extgcd(b, r) s, t = y, x-y*q return s, t, d def crt(b, m): r = 0 M = 1 for i in range(len(b)): s,t, d = extgcd(M, m[i]) if (b[i] - r) % d != 0: return [0, -1] lcm = M * m[i] // d r += M * ((b[i] - r) // d) * s M = lcm r %= M return r, M x,y = map(int,input().split()) x2,y2 = map(int,input().split()) x3,y3 = map(int,input().split()) r,M = crt([x,x2,x3], [y,y2,y3]) if M != -1 and r != 0: print(r) else: print(M)