結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,352 KB
testcase_01 AC 44 ms
57,216 KB
testcase_02 AC 44 ms
57,472 KB
testcase_03 AC 46 ms
57,344 KB
testcase_04 AC 47 ms
57,600 KB
testcase_05 AC 47 ms
57,728 KB
testcase_06 AC 46 ms
57,728 KB
testcase_07 AC 66 ms
60,288 KB
testcase_08 AC 66 ms
59,904 KB
testcase_09 AC 64 ms
60,160 KB
testcase_10 AC 65 ms
59,520 KB
testcase_11 AC 62 ms
60,032 KB
testcase_12 AC 218 ms
72,192 KB
testcase_13 AC 221 ms
72,064 KB
testcase_14 AC 219 ms
72,064 KB
testcase_15 AC 223 ms
72,320 KB
testcase_16 AC 219 ms
72,320 KB
testcase_17 AC 580 ms
76,672 KB
testcase_18 AC 797 ms
76,416 KB
testcase_19 AC 246 ms
72,832 KB
testcase_20 AC 1,447 ms
77,184 KB
testcase_21 AC 1,451 ms
77,440 KB
testcase_22 AC 1,683 ms
78,208 KB
testcase_23 AC 1,437 ms
77,184 KB
testcase_24 AC 1,423 ms
77,312 KB
testcase_25 AC 1,437 ms
77,440 KB
testcase_26 AC 1,433 ms
77,312 KB
testcase_27 AC 41 ms
51,968 KB
testcase_28 AC 984 ms
77,696 KB
testcase_29 AC 2,454 ms
77,568 KB
testcase_30 AC 2,472 ms
77,944 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
    divisors = sorted(divisors)
    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