結果
問題 | 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, groupbydef fast_prime_factorization_many(lst):# 素因数分解(ロー法、複数)from subprocess import Popen, PIPEres = 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 = 0if x == y:ans += x - 1fs = []ranges = []for f, gr in groupby(factors):fs.append(f)ranges.append(range(len(list(gr))+1))for t in product(*ranges):divisor = 1for n, f in zip(t, fs):divisor *= f ** nif divisor <= 2:continuea = divisor - 1denom = a * a - 1b, bm = divmod(a * x - y, denom)c, cm = divmod(a * y - x, denom)if bm == cm == 0 and b > 0 and c > 0:ans += 1Ans.append(ans)print("\n".join(map(str, Ans)))main()