結果

問題 No.1200 お菓子配り-3
ユーザー hir355hir355
提出日時 2020-08-28 22:18:37
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 833 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 77,124 KB
最終ジャッジ日時 2024-11-14 15:34:42
合計ジャッジ時間 21,334 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def search_devisors(n):
    res = []
    for a in range(1, int(n ** .5) + 2):
        if n % a == 0:
            if a == n // a:
                res.append(a)
            else:
                res.append(a)
                res.append(n // a)
    res.sort()
    return res

input = sys.stdin.readline
s = int(input())
for _ in range(s):
    x, y = map(int, input().split())
    x, y = max(x, y), min(x, y)
    if x == y:
        d = search_devisors(x)
        print(x - 1 + len(d) - 2)
    else:
        d = search_devisors(x - y)
        ans = 0
        for k in d:
            t = (x - y) // k
            a = k + 1
            if (x - a * t) % (a + 1) == 0:
                c = (x - a * t) // (a + 1)
                b = t + c
                if c > 0 and y == a * c + b:
                    ans += 1
        print(ans)
0