結果

問題 No.1200 お菓子配り-3
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-10-01 17:06:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 802 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 13,028 KB
最終ジャッジ日時 2023-09-21 07:00:09
合計ジャッジ時間 15,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,272 KB
testcase_01 AC 16 ms
7,888 KB
testcase_02 AC 30 ms
7,884 KB
testcase_03 AC 30 ms
7,724 KB
testcase_04 AC 29 ms
7,884 KB
testcase_05 AC 34 ms
7,804 KB
testcase_06 AC 28 ms
7,880 KB
testcase_07 AC 124 ms
7,884 KB
testcase_08 AC 124 ms
7,948 KB
testcase_09 AC 116 ms
7,720 KB
testcase_10 AC 115 ms
7,804 KB
testcase_11 AC 106 ms
7,884 KB
testcase_12 AC 976 ms
8,168 KB
testcase_13 AC 989 ms
8,188 KB
testcase_14 AC 994 ms
8,316 KB
testcase_15 AC 1,015 ms
8,308 KB
testcase_16 AC 996 ms
8,204 KB
testcase_17 AC 3,540 ms
8,304 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def main():
    input = sys.stdin.readline
    def make_divisors(n):
        lower_divisors , upper_divisors = [], []
        i = 1
        while i*i <= n:
            if n % i == 0:
                lower_divisors.append(i)
                if i != n // i:
                    upper_divisors.append(n//i)
            i += 1
        return lower_divisors + upper_divisors[::-1]
    Q = int(input())
    for _ in range(Q):
        x, y = map(int, input().split())
        if x == y:
            print(len(make_divisors(x)) + x - 3 + x % 2)
            continue
        ans = 0
        m = abs(x - y)
        mi = min(x, y)
        for i in make_divisors(m):
            n = m // i + 1
            ans += i < mi and not (mi - i) % (n + 1)
        print(ans)
if __name__ == "__main__":
    main()
0