結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー 14番14番
提出日時 2022-06-08 15:36:53
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,386 bytes
コンパイル時間 17,035 ms
コンパイル使用メモリ 445,036 KB
実行使用メモリ 172,460 KB
最終ジャッジ日時 2023-10-21 04:05:11
合計ジャッジ時間 40,717 ms
ジャッジサーバーID
(参考情報)
judge10 / 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>) {
         ^

ソースコード

diff #

fun main(args: Array<String>) {
    val t = readLine()!!.toInt()
    repeat(t){ _ ->
        println(getAns(readLine()!!.toLong()))

    }
}

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