結果

問題 No.1737 One to N
ユーザー 👑 箱
提出日時 2021-11-12 22:20:42
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 15,274 ms
コンパイル使用メモリ 428,732 KB
実行使用メモリ 56,520 KB
最終ジャッジ日時 2023-08-17 02:06:50
合計ジャッジ時間 26,473 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 314 ms
52,792 KB
testcase_01 AC 299 ms
52,640 KB
testcase_02 AC 293 ms
52,484 KB
testcase_03 AC 296 ms
54,584 KB
testcase_04 AC 302 ms
52,524 KB
testcase_05 AC 291 ms
54,372 KB
testcase_06 AC 301 ms
52,680 KB
testcase_07 AC 302 ms
54,388 KB
testcase_08 AC 301 ms
54,524 KB
testcase_09 AC 300 ms
54,576 KB
testcase_10 AC 294 ms
54,548 KB
testcase_11 AC 291 ms
56,520 KB
testcase_12 AC 299 ms
52,564 KB
testcase_13 AC 295 ms
52,852 KB
testcase_14 AC 293 ms
54,584 KB
testcase_15 AC 294 ms
54,760 KB
testcase_16 AC 290 ms
52,632 KB
testcase_17 AC 295 ms
52,540 KB
testcase_18 AC 296 ms
54,380 KB
testcase_19 AC 286 ms
54,492 KB
testcase_20 AC 286 ms
54,816 KB
testcase_21 AC 288 ms
52,764 KB
testcase_22 AC 289 ms
54,640 KB
testcase_23 AC 288 ms
54,708 KB
testcase_24 AC 292 ms
54,488 KB
testcase_25 AC 292 ms
52,616 KB
testcase_26 AC 290 ms
52,424 KB
testcase_27 AC 291 ms
52,812 KB
testcase_28 AC 293 ms
52,540 KB
testcase_29 AC 294 ms
54,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextLong()
    // region prime factorization
    var number = n
    var divisor = 2L
    val pf = mutableMapOf<Long, Int>()
    while (divisor * divisor <= number) {
        var count = 0
        while (number % divisor == 0L) {
            number /= divisor
            count++
        }
        if (count > 0) {
            pf[divisor] = count
        }
        divisor++
    }
    if (number > 1) pf[number] = 1
    // endregion
    var ans = 0L
    for ((p, e) in pf) {
        ans += p * e
    }
    println(ans)
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0