結果

問題 No.864 四方演算
ユーザー simansiman
提出日時 2021-10-14 14:13:11
言語 Ruby
(3.3.0)
結果
AC  
実行時間 146 ms / 1,000 ms
コード長 522 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 11,892 KB
実行使用メモリ 16,468 KB
最終ジャッジ日時 2023-10-17 19:22:38
合計ジャッジ時間 5,327 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
16,228 KB
testcase_01 AC 95 ms
16,228 KB
testcase_02 AC 94 ms
16,228 KB
testcase_03 AC 120 ms
16,468 KB
testcase_04 AC 97 ms
16,228 KB
testcase_05 AC 104 ms
16,404 KB
testcase_06 AC 121 ms
16,468 KB
testcase_07 AC 132 ms
16,468 KB
testcase_08 AC 146 ms
16,468 KB
testcase_09 AC 99 ms
16,404 KB
testcase_10 AC 97 ms
16,228 KB
testcase_11 AC 94 ms
16,228 KB
testcase_12 AC 99 ms
16,228 KB
testcase_13 AC 116 ms
16,468 KB
testcase_14 AC 99 ms
16,404 KB
testcase_15 AC 97 ms
16,236 KB
testcase_16 AC 100 ms
16,404 KB
testcase_17 AC 96 ms
16,228 KB
testcase_18 AC 98 ms
16,228 KB
testcase_19 AC 97 ms
16,228 KB
testcase_20 AC 97 ms
16,228 KB
testcase_21 AC 97 ms
16,228 KB
testcase_22 AC 99 ms
16,228 KB
testcase_23 AC 97 ms
16,228 KB
testcase_24 AC 97 ms
16,228 KB
testcase_25 AC 99 ms
16,228 KB
testcase_26 AC 97 ms
16,228 KB
testcase_27 AC 99 ms
16,228 KB
testcase_28 AC 99 ms
16,228 KB
testcase_29 AC 97 ms
16,228 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Integer
  def divisor_list
    require 'prime'

    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort - [1, self]
  end
end

N = gets.to_i
K = gets.to_i

ans = 0

K.divisor_list.each do |x|
  y = K / x
  a = x <= N ? x - 1 : [2 * N - x + 1, 0].max
  b = y <= N ? y - 1 : [2 * N - y + 1, 0].max

  ans += a * b
end

puts ans
0