結果

問題 No.1200 お菓子配り-3
ユーザー chielochielo
提出日時 2020-08-28 22:40:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,557 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 76,936 KB
最終ジャッジ日時 2024-04-26 23:56:15
合計ジャッジ時間 23,368 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
60,604 KB
testcase_01 AC 43 ms
58,660 KB
testcase_02 AC 49 ms
59,300 KB
testcase_03 AC 52 ms
58,956 KB
testcase_04 AC 48 ms
58,920 KB
testcase_05 AC 48 ms
58,728 KB
testcase_06 AC 49 ms
58,700 KB
testcase_07 AC 97 ms
62,924 KB
testcase_08 AC 102 ms
63,024 KB
testcase_09 AC 96 ms
62,608 KB
testcase_10 AC 96 ms
63,252 KB
testcase_11 AC 97 ms
63,780 KB
testcase_12 AC 514 ms
76,280 KB
testcase_13 AC 515 ms
74,576 KB
testcase_14 AC 523 ms
75,996 KB
testcase_15 AC 530 ms
75,972 KB
testcase_16 AC 512 ms
74,036 KB
testcase_17 AC 1,679 ms
76,484 KB
testcase_18 AC 2,363 ms
76,520 KB
testcase_19 AC 609 ms
76,152 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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