結果

問題 No.1200 お菓子配り-3
ユーザー nagissnagiss
提出日時 2020-08-29 04:37:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 483 ms / 4,000 ms
コード長 1,222 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 17,008 KB
最終ジャッジ日時 2024-05-01 00:03:54
合計ジャッジ時間 6,729 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
11,904 KB
testcase_01 AC 43 ms
11,904 KB
testcase_02 AC 43 ms
11,904 KB
testcase_03 AC 44 ms
11,904 KB
testcase_04 AC 44 ms
11,904 KB
testcase_05 AC 44 ms
11,904 KB
testcase_06 AC 43 ms
11,904 KB
testcase_07 AC 48 ms
11,904 KB
testcase_08 AC 47 ms
12,032 KB
testcase_09 AC 46 ms
11,904 KB
testcase_10 AC 49 ms
11,904 KB
testcase_11 AC 45 ms
12,032 KB
testcase_12 AC 77 ms
12,288 KB
testcase_13 AC 80 ms
12,288 KB
testcase_14 AC 79 ms
12,416 KB
testcase_15 AC 79 ms
12,288 KB
testcase_16 AC 77 ms
12,288 KB
testcase_17 AC 174 ms
13,440 KB
testcase_18 AC 232 ms
14,080 KB
testcase_19 AC 88 ms
12,416 KB
testcase_20 AC 409 ms
16,152 KB
testcase_21 AC 413 ms
16,040 KB
testcase_22 AC 483 ms
17,008 KB
testcase_23 AC 410 ms
16,216 KB
testcase_24 AC 410 ms
16,148 KB
testcase_25 AC 400 ms
16,148 KB
testcase_26 AC 405 ms
15,964 KB
testcase_27 AC 43 ms
11,776 KB
testcase_28 AC 256 ms
16,996 KB
testcase_29 AC 305 ms
16,876 KB
testcase_30 AC 308 ms
16,996 KB
testcase_31 AC 43 ms
11,904 KB
testcase_32 AC 43 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0