結果
問題 |
No.1200 お菓子配り-3
|
ユーザー |
![]() |
提出日時 | 2020-08-28 22:04:20 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,310 bytes |
コンパイル時間 | 296 ms |
コンパイル使用メモリ | 82,396 KB |
実行使用メモリ | 78,384 KB |
最終ジャッジ日時 | 2024-11-14 14:54:20 |
合計ジャッジ時間 | 21,335 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 WA * 2 |
ソースコード
def make_divisors(n: int) -> list: """自然数nの約数を列挙したリストを出力する 計算量: O(sqrt(N)) 入出力例: 12 -> [1, 2, 3, 4, 6, 12] """ divisors = [] for k in range(1, int(n ** 0.5) + 1): if n % k == 0: divisors.append(k) if k != n // k: divisors.append(n // k) divisors = sorted(divisors) return divisors s = int(input()) memo = {} for _ in range(s): x, y = map(int, input().split()) if x < y: x, y = y, x sum_ = x + y diff = x - y cnt = 0 if (x, y) in memo: print(memo[x, y]) continue if diff == 0: cnt += x - 1 # b * (a + 1) = x divisors = make_divisors(x) cnt += (len(divisors) - 1) memo[(x, y)] = cnt print(cnt) continue divisors = make_divisors(diff) for div in divisors: a = div + 1 # b + c = sum_ // (a + 1) # b - c = diff // (a - 1) if sum_ % (a + 1) != 0: continue t1 = sum_ // (a + 1) t2 = diff // (a - 1) if (t1 + t2) % 2 == 1: continue b, c = (t1 + t2) // 2, (t1 - t2) // 2 if b > 0 and c > 0: cnt += 1 memo[(x, y)] = cnt print(cnt)