結果

問題 No.1200 お菓子配り-3
ユーザー neterukunneterukun
提出日時 2020-08-28 22:02:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,186 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,056 KB
最終ジャッジ日時 2024-04-26 22:57:25
合計ジャッジ時間 22,400 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,352 KB
testcase_01 AC 43 ms
57,052 KB
testcase_02 AC 47 ms
57,856 KB
testcase_03 AC 47 ms
57,728 KB
testcase_04 AC 47 ms
57,600 KB
testcase_05 AC 47 ms
57,472 KB
testcase_06 AC 47 ms
57,856 KB
testcase_07 AC 66 ms
60,032 KB
testcase_08 AC 65 ms
59,904 KB
testcase_09 AC 65 ms
60,032 KB
testcase_10 AC 67 ms
59,904 KB
testcase_11 AC 64 ms
60,032 KB
testcase_12 AC 209 ms
71,040 KB
testcase_13 AC 215 ms
71,296 KB
testcase_14 AC 215 ms
71,296 KB
testcase_15 AC 215 ms
71,296 KB
testcase_16 AC 218 ms
71,040 KB
testcase_17 AC 572 ms
76,288 KB
testcase_18 AC 794 ms
76,928 KB
testcase_19 AC 242 ms
71,808 KB
testcase_20 AC 1,441 ms
76,672 KB
testcase_21 AC 1,429 ms
76,800 KB
testcase_22 AC 1,672 ms
76,800 KB
testcase_23 AC 1,485 ms
76,544 KB
testcase_24 AC 1,403 ms
76,800 KB
testcase_25 AC 1,430 ms
76,544 KB
testcase_26 AC 1,440 ms
76,416 KB
testcase_27 AC 41 ms
52,096 KB
testcase_28 AC 1,142 ms
76,416 KB
testcase_29 AC 3,024 ms
76,544 KB
testcase_30 AC 3,034 ms
77,056 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())
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 diff == 0:
        cnt += x - 1
        # b * (a + 1) = x
        divisors = make_divisors(x)
        cnt += (len(divisors) - 1)

        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

    print(cnt)
0