結果

問題 No.1200 お菓子配り-3
ユーザー gew1fw
提出日時 2025-06-12 14:27:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,793 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 79,384 KB
最終ジャッジ日時 2025-06-12 14:27:32
合計ジャッジ時間 21,380 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def get_divisors(n):
    divisors = set()
    for i in range(1, int(math.isqrt(abs(n))) + 1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(-i)
            divisors.add(n // i)
            divisors.add(-n // i)
    return divisors

def count_solutions(X, Y):
    D = Y - X
    solutions = 0
    if D == 0:
        total = 2 * Y
        for A in range(2, int(math.isqrt(total)) + 2):
            if (A + 1) != 0 and total % (A + 1) == 0:
                C = (Y * A - X) // (A * A - 1)
                if C <= 0:
                    continue
                if (X - C) % A != 0:
                    continue
                B = (X - C) // A
                if B <= 0:
                    continue
                solutions += 1
    else:
        divisors = get_divisors(D)
        for d in divisors:
            if d <= 0:
                continue
            A = d + 1
            total = X + Y
            if (A + 1) == 0:
                continue
            if total % (A + 1) != 0:
                continue
            numerator = Y * A - X
            denominator = A * A - 1
            if denominator == 0:
                continue
            if numerator % denominator != 0:
                continue
            C = numerator // denominator
            if C <= 0:
                continue
            if (X - C) % A != 0:
                continue
            B = (X - C) // A
            if B <= 0:
                continue
            solutions += 1
    return solutions

def main():
    input = sys.stdin.read().split()
    S = int(input[0])
    idx = 1
    for _ in range(S):
        X = int(input[idx])
        Y = int(input[idx + 1])
        idx += 2
        print(count_solutions(X, Y))

if __name__ == '__main__':
    main()
0