結果
問題 |
No.1200 お菓子配り-3
|
ユーザー |
![]() |
提出日時 | 2020-08-29 04:37:39 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 480 ms / 4,000 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 216 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 16,880 KB |
最終ジャッジ日時 | 2024-11-20 22:52:29 |
合計ジャッジ時間 | 6,756 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
外部呼び出し有り |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 |
ソースコード
from itertools import product, groupby def fast_prime_factorization_many(lst): # 素因数分解(ロー法、複数) from subprocess import Popen, PIPE res = Popen(["factor"] + list(map(str, lst)), stdout=PIPE).communicate()[0].split(b"\n")[:-1] return [list(map(int, r.split()[1:])) for r in res] def main(): S = int(input()) XY = [list(map(int, input().split())) for _ in range(S)] Factors = fast_prime_factorization_many([x+y for x, y in XY]) Ans = [] for (x, y), factors in zip(XY, Factors): ans = 0 if x == y: ans += x - 1 fs = [] ranges = [] for f, gr in groupby(factors): fs.append(f) ranges.append(range(len(list(gr))+1)) for t in product(*ranges): divisor = 1 for n, f in zip(t, fs): divisor *= f ** n if divisor <= 2: continue a = divisor - 1 denom = a * a - 1 b, bm = divmod(a * x - y, denom) c, cm = divmod(a * y - x, denom) if bm == cm == 0 and b > 0 and c > 0: ans += 1 Ans.append(ans) print("\n".join(map(str, Ans))) main()