結果

問題 No.1200 お菓子配り-3
ユーザー neterukunneterukun
提出日時 2020-08-28 22:09:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,325 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,132 KB
実行使用メモリ 78,204 KB
最終ジャッジ日時 2024-04-26 23:18:28
合計ジャッジ時間 19,987 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,020 KB
testcase_01 AC 40 ms
59,040 KB
testcase_02 AC 42 ms
58,476 KB
testcase_03 AC 44 ms
58,484 KB
testcase_04 AC 42 ms
58,380 KB
testcase_05 AC 43 ms
57,864 KB
testcase_06 AC 42 ms
57,972 KB
testcase_07 AC 59 ms
59,532 KB
testcase_08 AC 60 ms
61,964 KB
testcase_09 AC 58 ms
59,628 KB
testcase_10 AC 59 ms
59,880 KB
testcase_11 AC 56 ms
60,112 KB
testcase_12 AC 192 ms
68,772 KB
testcase_13 AC 196 ms
68,480 KB
testcase_14 AC 190 ms
68,496 KB
testcase_15 AC 196 ms
69,372 KB
testcase_16 AC 194 ms
69,628 KB
testcase_17 AC 548 ms
74,264 KB
testcase_18 AC 764 ms
76,616 KB
testcase_19 AC 222 ms
68,876 KB
testcase_20 AC 1,388 ms
77,308 KB
testcase_21 AC 1,410 ms
77,812 KB
testcase_22 AC 1,631 ms
77,804 KB
testcase_23 AC 1,398 ms
77,356 KB
testcase_24 AC 1,378 ms
77,440 KB
testcase_25 AC 1,391 ms
77,420 KB
testcase_26 AC 1,382 ms
77,660 KB
testcase_27 AC 37 ms
52,816 KB
testcase_28 AC 897 ms
78,028 KB
testcase_29 AC 2,386 ms
77,652 KB
testcase_30 AC 2,378 ms
78,204 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline


def make_divisors(n: int) -> list:
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n ** 0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k: 
                divisors.append(n // k)
    return divisors


s = int(input())
memo = {}
for _ in range(s):
    x, y = map(int, input().split())
    
    if x < y:
        x, y = y, x
    
    sum_ = x + y
    diff = x - y
    
    cnt = 0
    if (x, y) in memo:
        print(memo[x, y])
        continue

    if diff == 0:
        cnt += x - 1
        # b * (a + 1) = x
        divisors = make_divisors(x)
        cnt += (len(divisors) - 1)
        memo[(x, y)] = cnt
        print(cnt)
        continue

    divisors = make_divisors(diff)
    for div in divisors:
        a = div + 1
  
        # b + c = sum_ // (a + 1)
        # b - c = diff // (a - 1)
        if sum_ % (a + 1) != 0:
            continue

        t1 = sum_ // (a + 1)
        t2 = diff // (a - 1)

        if (t1 + t2) % 2 == 1:
            continue
        b, c = (t1 + t2) // 2, (t1 - t2) // 2

        if b > 0 and c > 0:
            cnt += 1
    memo[(x, y)] = cnt
    print(cnt)
0