結果

問題 No.1737 One to N
ユーザー 👑 箱星箱星
提出日時 2021-11-12 22:20:42
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 260 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 13,036 ms
コンパイル使用メモリ 449,492 KB
実行使用メモリ 50,252 KB
最終ジャッジ日時 2024-05-04 09:20:49
合計ジャッジ時間 22,005 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 241 ms
50,132 KB
testcase_01 AC 239 ms
50,088 KB
testcase_02 AC 242 ms
50,028 KB
testcase_03 AC 249 ms
50,088 KB
testcase_04 AC 243 ms
50,148 KB
testcase_05 AC 246 ms
50,148 KB
testcase_06 AC 248 ms
50,240 KB
testcase_07 AC 251 ms
49,932 KB
testcase_08 AC 251 ms
50,152 KB
testcase_09 AC 250 ms
50,152 KB
testcase_10 AC 253 ms
50,208 KB
testcase_11 AC 248 ms
50,252 KB
testcase_12 AC 255 ms
50,104 KB
testcase_13 AC 246 ms
49,988 KB
testcase_14 AC 250 ms
49,936 KB
testcase_15 AC 251 ms
50,144 KB
testcase_16 AC 249 ms
50,024 KB
testcase_17 AC 246 ms
49,936 KB
testcase_18 AC 250 ms
50,052 KB
testcase_19 AC 243 ms
50,108 KB
testcase_20 AC 246 ms
50,096 KB
testcase_21 AC 249 ms
49,940 KB
testcase_22 AC 248 ms
50,096 KB
testcase_23 AC 260 ms
50,128 KB
testcase_24 AC 259 ms
50,108 KB
testcase_25 AC 254 ms
49,920 KB
testcase_26 AC 249 ms
49,984 KB
testcase_27 AC 246 ms
50,024 KB
testcase_28 AC 248 ms
49,896 KB
testcase_29 AC 246 ms
50,176 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