結果
問題 |
No.816 Beautiful tuples
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:11:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 43 ms / 1,500 ms |
コード長 | 604 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,660 KB |
実行使用メモリ | 59,180 KB |
最終ジャッジ日時 | 2025-03-20 21:11:27 |
合計ジャッジ時間 | 1,487 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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))