結果

問題 No.1659 Product of Divisors
ユーザー simansiman
提出日時 2022-08-19 19:45:05
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 713 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 30,848 KB
最終ジャッジ日時 2024-04-16 22:41:30
合計ジャッジ時間 4,781 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
17,664 KB
testcase_01 AC 443 ms
16,768 KB
testcase_02 AC 186 ms
13,312 KB
testcase_03 AC 102 ms
12,160 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

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
  end
end

N, K = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

cache = []
nums = N.divisor_list
cache = Hash.new

nums.each do |n|
  cache[n] = n.divisor_list
end

dp = Hash.new(0)
dp[N] = 1

K.times do |i|
  temp = Hash.new(0)

  nums.each do |n|
    cache[n].each do |e, _cnt|
      nv = n / e
      temp[nv] += dp[n]
      temp[nv] %= MOD
    end
  end

  dp = temp
end

puts dp.values.sum % MOD
0