結果

問題 No.1200 お菓子配り-3
ユーザー chielochielo
提出日時 2020-08-28 22:38:10
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,471 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 83,460 KB
最終ジャッジ日時 2024-04-26 23:53:29
合計ジャッジ時間 24,935 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
60,424 KB
testcase_01 AC 41 ms
59,740 KB
testcase_02 AC 48 ms
59,700 KB
testcase_03 AC 48 ms
59,404 KB
testcase_04 AC 50 ms
59,784 KB
testcase_05 AC 49 ms
59,580 KB
testcase_06 AC 49 ms
59,804 KB
testcase_07 AC 104 ms
63,288 KB
testcase_08 AC 104 ms
63,828 KB
testcase_09 AC 100 ms
63,324 KB
testcase_10 AC 99 ms
63,256 KB
testcase_11 AC 103 ms
62,856 KB
testcase_12 AC 552 ms
76,140 KB
testcase_13 AC 561 ms
74,020 KB
testcase_14 AC 553 ms
75,960 KB
testcase_15 AC 561 ms
74,700 KB
testcase_16 AC 547 ms
73,680 KB
testcase_17 AC 1,787 ms
76,492 KB
testcase_18 AC 2,572 ms
76,540 KB
testcase_19 AC 650 ms
75,988 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
    s, t = [], []
    for a in range(1, x + y):
        if a * a > x + y:
            break
        if (x + y) % a:
            continue
        s.append(a - 1)
        if (x + y) // a != a:
            s.append((x + y) // a - 1)
    for a in range(1, x - y):
        if a * a > x - y:
            break
        if (x - y) % a:
            continue
        t.append(a + 1)
        if (x - y) // a != a:
            t.append((x - y) // a + 1)
    s.sort()
    t.sort()
    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