結果
| 問題 | No.186 中華風 (Easy) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-08 12:32:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,287 bytes |
| 記録 | |
| コンパイル時間 | 339 ms |
| コンパイル使用メモリ | 82,652 KB |
| 実行使用メモリ | 62,860 KB |
| 最終ジャッジ日時 | 2025-12-08 12:32:16 |
| 合計ジャッジ時間 | 2,616 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 17 |
ソースコード
import sys
from functools import reduce
def input(): return sys.stdin.readline().rstrip('\n')
def factorize(n):
ans = []
i = 2
while i * i <= n:
if n % i == 0:
c = 0
while n % i == 0:
c += 1
n //= i
ans.append((i, c))
i += 1
if n != 1:
ans.append((n, 1))
return ans
def main():
rems = {}
def add_prime(q, p, c):
if p in rems:
aq, ac = rems[p]
if ac > c:
aq, q, ac, c = q, aq, c, ac
if q % (p ** ac) != aq:
return False
rems[p] = (q, c)
return True
def add(x, y):
f = factorize(y)
for (p, c) in f:
if not add_prime(x % (p ** c), p, c):
return False
return True
n = 3
for _ in range(n):
x, y = map(int, input().split())
if not add(x, y):
return -1
crt = [(q, p ** c) for p, (q, c) in rems.items()]
M = reduce(lambda x, y: x * y, (b for a, b in crt), 1)
ans = sum(q * (M // m) * pow(M // m, -1, m) for (q, m) in crt) % M
return (M if ans == 0 else ans) % 1_000_000_007
if __name__ == '__main__':
ret = main()
if ret is not None:
print(ret)