結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー 14番14番
提出日時 2022-06-08 15:42:17
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,456 bytes
コンパイル時間 17,950 ms
コンパイル使用メモリ 463,980 KB
実行使用メモリ 113,136 KB
最終ジャッジ日時 2023-10-21 04:05:59
合計ジャッジ時間 32,581 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:5:13: warning: 'appendln(Long): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
        ans.appendln(getAns(readLine()!!.toLong()))
            ^

ソースコード

diff #

fun main(args: Array<String>) {
    val t = readLine()!!.toInt()
    val ans = java.lang.StringBuilder()
    repeat(t){ _ ->
        ans.appendln(getAns(readLine()!!.toLong()))
    }
    print(ans.toString())
}

fun getAns(num:Long):Long {
    if(num == 1L) {
        return 2
    }
    if(num == 2L) {
        return 6
    }
    val prime = primeDivide(num)
    val keys = prime.keys.toList()
    var tmp = Long.MAX_VALUE
    for(i in primeList.indices) {
        if(keys.size <= i) {
            tmp = primeList[i]
            break
        }
        if(keys[i] != primeList[i]) {
            tmp = primeList[i]
            break
        }
    }
    val total = prime.values.sum()
    return Math.min(tmp, 1L shl total) * num
}
val primeList = mutableListOf<Long>().also {
    val max = 1_000_000
    val flag = BooleanArray(max+1)
    for(i in 2..max) {
        if(flag[i]) {
            continue
        }
        it.add(i.toLong())
        for(j in 1..max) {
            if(i*j>max) {
                break
            }
            flag[i*j] = true
        }
    }
}

fun primeDivide(num:Long):Map<Long,Int> {
    var n = num
    val ret = mutableMapOf<Long,Int>()
    for(prime in primeList) {
        if(prime*prime > n) {
            if(n > 1) {
                ret[n] = 1
            }
            break
        }
        while (n % prime == 0L) {
            ret[prime] = (ret[prime]?:0)+1
            n /= prime
        }
    }
    return ret
}
0