結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,556 KB
testcase_01 AC 47 ms
61,308 KB
testcase_02 AC 49 ms
60,488 KB
testcase_03 AC 50 ms
61,236 KB
testcase_04 AC 49 ms
61,796 KB
testcase_05 AC 50 ms
60,688 KB
testcase_06 AC 48 ms
61,332 KB
testcase_07 AC 66 ms
64,024 KB
testcase_08 AC 68 ms
64,008 KB
testcase_09 AC 66 ms
63,728 KB
testcase_10 AC 64 ms
62,932 KB
testcase_11 AC 65 ms
62,872 KB
testcase_12 AC 202 ms
74,416 KB
testcase_13 AC 209 ms
74,104 KB
testcase_14 AC 209 ms
74,560 KB
testcase_15 AC 211 ms
74,164 KB
testcase_16 AC 208 ms
73,752 KB
testcase_17 AC 568 ms
78,084 KB
testcase_18 AC 777 ms
77,864 KB
testcase_19 AC 236 ms
75,056 KB
testcase_20 AC 1,430 ms
77,652 KB
testcase_21 AC 1,415 ms
77,876 KB
testcase_22 AC 1,659 ms
78,240 KB
testcase_23 AC 1,426 ms
77,872 KB
testcase_24 AC 1,428 ms
77,696 KB
testcase_25 AC 1,410 ms
77,640 KB
testcase_26 AC 1,408 ms
77,636 KB
testcase_27 AC 45 ms
55,756 KB
testcase_28 AC 910 ms
78,632 KB
testcase_29 AC 2,391 ms
77,740 KB
testcase_30 AC 2,391 ms
77,668 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import functools
import sys
input = sys.stdin.buffer.readline

@functools.lru_cache(maxsize=10**5)
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 diff == 0:
        cnt += x - 1
        # b * (a + 1) = x
        cnt += (len(make_divisors(x)) - 1)
        print(cnt)
        continue

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

        t1, t2 = sum_ // (a + 1), 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