結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー 👑 箱
提出日時 2020-05-29 21:25:01
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 318 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 17,171 ms
コンパイル使用メモリ 448,028 KB
実行使用メモリ 49,988 KB
最終ジャッジ日時 2024-04-23 20:06:16
合計ジャッジ時間 19,727 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 318 ms
49,984 KB
testcase_01 AC 298 ms
49,676 KB
testcase_02 AC 295 ms
49,988 KB
testcase_03 AC 301 ms
49,828 KB
testcase_04 AC 294 ms
49,624 KB
testcase_05 AC 303 ms
49,836 KB
testcase_06 AC 293 ms
49,896 KB
testcase_07 AC 296 ms
49,988 KB
testcase_08 AC 300 ms
49,804 KB
testcase_09 AC 294 ms
49,576 KB
testcase_10 AC 300 ms
49,820 KB
testcase_11 AC 299 ms
49,940 KB
testcase_12 AC 300 ms
49,852 KB
testcase_13 AC 296 ms
49,620 KB
testcase_14 AC 292 ms
49,568 KB
testcase_15 AC 290 ms
49,860 KB
testcase_16 AC 294 ms
49,692 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:39:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    var n = sc.nextInt()
    val pf = mutableMapOf<Int, Int>()
    var d = 2
    while (d * d <= n) {
        var count = 0
        while (n % d == 0) {
            count++
            n /= d
        }
        if (count > 0) {
            pf[d] = count
        }
        d++
    }
    if (n > 1) {
        pf[n] = 1
    }
    var a = 1
    var b = 1
    for ((p, e) in pf) {
        for (i in 0 until e / 2) {
            a *= p
        }
        if (e % 2 == 1) {
            b *= p
        }
    }
    println("$a $b")
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    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()
    fun ready() = br.ready()
}
0