結果

問題 No.864 四方演算
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2021-05-31 23:42:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 917 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 58,624 KB
最終ジャッジ日時 2024-04-26 09:39:18
合計ジャッジ時間 2,605 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,224 KB
testcase_01 AC 56 ms
57,856 KB
testcase_02 AC 53 ms
58,112 KB
testcase_03 AC 53 ms
57,472 KB
testcase_04 AC 58 ms
57,856 KB
testcase_05 AC 51 ms
57,472 KB
testcase_06 AC 54 ms
57,728 KB
testcase_07 AC 53 ms
57,600 KB
testcase_08 AC 52 ms
57,472 KB
testcase_09 AC 49 ms
57,856 KB
testcase_10 AC 47 ms
57,856 KB
testcase_11 AC 45 ms
57,856 KB
testcase_12 AC 53 ms
57,984 KB
testcase_13 AC 49 ms
57,600 KB
testcase_14 AC 45 ms
57,728 KB
testcase_15 AC 55 ms
57,728 KB
testcase_16 AC 53 ms
57,728 KB
testcase_17 AC 56 ms
57,728 KB
testcase_18 AC 54 ms
58,624 KB
testcase_19 AC 52 ms
57,856 KB
testcase_20 AC 56 ms
58,112 KB
testcase_21 AC 54 ms
58,112 KB
testcase_22 AC 53 ms
58,368 KB
testcase_23 AC 44 ms
57,728 KB
testcase_24 AC 51 ms
57,600 KB
testcase_25 AC 47 ms
58,240 KB
testcase_26 AC 52 ms
58,240 KB
testcase_27 AC 40 ms
52,096 KB
testcase_28 AC 39 ms
52,352 KB
testcase_29 AC 39 ms
51,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# くくり出すと良さそう。
# ab + bc + cd + da = k
# b(a+c) + d(c+a) = k
# (a+c) * (b+d) = k

# k の約数を列挙して、 (i+j) の場合の数で良い感じにする

n = int(input())
k = int(input())
ans = 0

# x を (i+j) に分解する場合の数(0 < i, j < n)
def division(x, n):
    if x > 2*n:
        return 0
    return n - abs(x - n - 1)

# (1, k) のペアはどうせ i+j に分解できないので飛ばす
for i in range(2, int(k ** 0.5) + 1):
    if k % i != 0: # i で割り切れなければ飛ばす
        continue

    j = k // i

    # i * j == k となるやつを見つけたので i を (a+c) みたいに分解する数を考える。
    # division(i) * division(j) が 場合の数
    cnt = division(i, n) * division(j, n)

    # i != j なら (i, j) の組み合わせと (j, i) の組み合わせがある
    if i != j:
        cnt *= 2

    ans += cnt

print(ans)
0