結果

問題 No.2365 Present of good number
ユーザー simansiman
提出日時 2023-07-11 06:53:38
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 909 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 11,436 KB
実行使用メモリ 15,788 KB
最終ジャッジ日時 2023-10-10 01:35:46
合計ジャッジ時間 5,836 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
15,476 KB
testcase_01 AC 98 ms
15,524 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 100 ms
15,648 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 96 ms
15,544 KB
testcase_18 AC 96 ms
15,612 KB
testcase_19 WA -
testcase_20 AC 98 ms
15,412 KB
testcase_21 AC 98 ms
15,604 KB
testcase_22 WA -
testcase_23 AC 98 ms
15,660 KB
testcase_24 AC 96 ms
15,628 KB
testcase_25 WA -
testcase_26 AC 97 ms
15,408 KB
testcase_27 AC 97 ms
15,500 KB
testcase_28 AC 98 ms
15,540 KB
testcase_29 AC 98 ms
15,600 KB
testcase_30 AC 96 ms
15,564 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 99 ms
15,520 KB
testcase_37 AC 97 ms
15,672 KB
testcase_38 AC 96 ms
15,564 KB
testcase_39 AC 97 ms
15,456 KB
testcase_40 AC 98 ms
15,632 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

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

def ff(a, k)
  return a if k <= 0

  nums = a.prime_division
  res = 1

  nums.each do |v, e|
    res *= (v + 1).pow(e)
  end

  ff(res, k - 1)
end

def f(a, k)
  return a if k <= 0

  nums = a.prime_division
  if nums.last[0] <= 3 && nums.size == 2
    cnt_2 = nums[0][1]
    cnt_3 = nums[1][1]

    d = k / 2
    cnt_2 = (cnt_2 * 2.pow(d, MOD)) % MOD
    cnt_3 = (cnt_3 * 2.pow(d, MOD)) % MOD

    if k % 2 != 0
      cnt_2, cnt_3 = 2 * cnt_3, cnt_2
    end

    return (2.pow(cnt_2, MOD) * 3.pow(cnt_3, MOD)) % MOD
  elsif nums.last[0] == 2
    cnt = nums[0][1]
    d = k / 2

    cnt = (cnt * 2.pow(d, MOD)) % MOD

    if k % 2 == 0
      return 2.pow(cnt, MOD)
    else
      return 3.pow(cnt, MOD)
    end
  end

  res = 1

  nums.each do |v, e|
    res *= (v + 1).pow(e)
  end

  f(res, k - 1)
end

# pp ff(N, K) % MOD
pp f(N, K) % MOD
0