結果
| 問題 |
No.1200 お菓子配り-3
|
| コンテスト | |
| ユーザー |
nagiss
|
| 提出日時 | 2020-08-29 04:32:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,178 bytes |
| コンパイル時間 | 247 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 16,992 KB |
| 最終ジャッジ日時 | 2024-11-14 17:18:10 |
| 合計ジャッジ時間 | 6,528 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 WA * 2 |
ソースコード
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
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()
nagiss