結果

問題 No.1200 お菓子配り-3
ユーザー chielo
提出日時 2020-08-28 22:40:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,557 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 129,404 KB
最終ジャッジ日時 2024-11-14 16:09:21
合計ジャッジ時間 56,420 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 2 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

def subsolve(x):
    ans = 0
    for i in range(1, x):
        if i * i > x:
            break
        if x % i:
            continue
        if x // i - 1 > 0:
            ans += 1
        if x != i * i and x // (x // i) - 1 > 0:
            ans += 1
    ans += x
    print(ans)

def solve():
    x, y = map(int, input().split())
    if x == y:
        subsolve(x)
        return
    if x < y:
        x, y = y, x
    ans = 0
    su, sv, tu, tv = [], [], [], []
    for a in range(1, x + y):
        if a * a > x + y:
            break
        if (x + y) % a:
            continue
        su.append(a - 1)
        if (x + y) // a != a:
            sv.append((x + y) // a - 1)
    for a in range(1, x - y):
        if a * a > x - y:
            break
        if (x - y) % a:
            continue
        tu.append(a + 1)
        if (x - y) // a != a:
            tv.append((x - y) // a + 1)
    sv.reverse()
    s = su
    s.extend(sv)
    tv.reverse()
    t = tu
    t.extend(tv)
    i, j = 0, 0
    ans = 0
    while i < len(s) and j < len(t):
        if s[i] != t[j]:
            if s[i] < t[j]:
                i += 1
            else:
                j += 1
        else:
            a = s[i]
            if a - 1 > 0:
                bpc = (x + y) // (a + 1)
                bmc = (x - y) // (a - 1)
                b = (bpc + bmc) // 2
                c = x - a * b
                if b > 0 and c > 0 and a * c + b == y:
                    ans += 1
            i += 1
            j += 1
    print(ans)
t = int(input())
for _ in range(t):
    solve()
0