結果

問題 No.847 Divisors of Power
ユーザー pekempeypekempey
提出日時 2019-07-25 05:09:22
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 735 bytes
コンパイル時間 14,764 ms
コンパイル使用メモリ 446,564 KB
実行使用メモリ 57,128 KB
最終ジャッジ日時 2024-04-30 21:08:19
合計ジャッジ時間 20,647 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 269 ms
57,028 KB
testcase_01 AC 269 ms
56,920 KB
testcase_02 AC 282 ms
56,996 KB
testcase_03 AC 265 ms
56,888 KB
testcase_04 AC 302 ms
57,128 KB
testcase_05 AC 267 ms
56,960 KB
testcase_06 AC 265 ms
57,020 KB
testcase_07 AC 267 ms
57,032 KB
testcase_08 AC 265 ms
56,892 KB
testcase_09 AC 273 ms
57,020 KB
testcase_10 AC 273 ms
57,092 KB
testcase_11 AC 275 ms
57,012 KB
testcase_12 AC 281 ms
56,908 KB
testcase_13 AC 279 ms
57,112 KB
testcase_14 AC 277 ms
57,032 KB
testcase_15 AC 289 ms
56,960 KB
testcase_16 AC 283 ms
56,984 KB
testcase_17 AC 281 ms
57,000 KB
testcase_18 AC 271 ms
57,128 KB
testcase_19 AC 292 ms
56,964 KB
testcase_20 AC 268 ms
56,880 KB
testcase_21 AC 292 ms
57,088 KB
testcase_22 AC 278 ms
56,992 KB
testcase_23 AC 287 ms
56,888 KB
testcase_24 AC 293 ms
56,960 KB
testcase_25 AC 267 ms
56,884 KB
testcase_26 AC 296 ms
56,904 KB
testcase_27 AC 299 ms
57,108 KB
testcase_28 AC 272 ms
56,968 KB
testcase_29 AC 271 ms
56,868 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:31:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

fun readLongs(): List<Long> = readLine()!!.split(" ").map{it.toLong()}

fun factors(n_: Long): Map<Long, Long> {
  var n = n_
  var ans: MutableMap<Long, Long> = mutableMapOf()
  var i = 2L
  while (i * i <= n) {
    while (n % i == 0L) {
      ans[i] = (ans[i] ?: 0) + 1
      n /= i
    }
    i += 1
  }
  if (n != 1L) ans[n] = 1
  return ans
}

fun dfs(k: Int, x_: Long, fs: List<Pair<Long, Long>>): Int {
  var x = x_
  if (k == fs.size) return 1
  var ans = 0
  var i = 0L
  while (x >= 1L && i <= fs[k].second) {
    ans += dfs(k+1, x, fs)
    x /= fs[k].first
    i++
  }
  return ans
}

fun main(args: Array<String>) {
  val (N, K, M) = readLongs()
  val fs = factors(N).map{ (k, v) -> Pair(k, v*K) }
  println(dfs(0, M, fs))
}
0