結果
問題 | No.1200 お菓子配り-3 |
ユーザー |
![]() |
提出日時 | 2020-08-28 22:14:49 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,201 bytes |
コンパイル時間 | 381 ms |
コンパイル使用メモリ | 82,096 KB |
実行使用メモリ | 78,616 KB |
最終ジャッジ日時 | 2024-11-14 15:30:19 |
合計ジャッジ時間 | 20,694 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 WA * 2 |
ソースコード
import functools import sys input = sys.stdin.buffer.readline @functools.lru_cache(maxsize=10**5) 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) 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 diff == 0: cnt += x - 1 # b * (a + 1) = x cnt += (len(make_divisors(x)) - 1) print(cnt) continue for div in make_divisors(diff): a = div + 1 # b + c = sum_ // (a + 1) # b - c = diff // (a - 1) if sum_ % (a + 1) != 0: continue t1, t2 = sum_ // (a + 1), 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 print(cnt)