結果
問題 | No.816 Beautiful tuples |
ユーザー |
![]() |
提出日時 | 2025-03-20 18:58:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 40 ms / 1,500 ms |
コード長 | 604 bytes |
コンパイル時間 | 147 ms |
コンパイル使用メモリ | 82,276 KB |
実行使用メモリ | 59,396 KB |
最終ジャッジ日時 | 2025-03-20 18:59:53 |
合計ジャッジ時間 | 1,441 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
import math def find_min_c(a, b): s = a + b # Generate all divisors of s divisors = set() for i in range(1, int(math.isqrt(s)) + 1): if s % i == 0: divisors.add(i) divisors.add(s // i) sorted_divisors = sorted(divisors) # Check each divisor in order for c in sorted_divisors: if c == a or c == b: continue # Check if (a + c) is divisible by b and (b + c) is divisible by a if (a + c) % b == 0 and (b + c) % a == 0: return c return -1 a, b = map(int, input().split()) print(find_min_c(a, b))