結果

問題 No.2380 Sylow P-subgroup
ユーザー 👑 箱
提出日時 2023-01-12 18:31:17
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 430 bytes
コンパイル時間 12,792 ms
コンパイル使用メモリ 431,444 KB
実行使用メモリ 57,020 KB
最終ジャッジ日時 2024-04-30 21:56:44
合計ジャッジ時間 19,620 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 322 ms
56,956 KB
testcase_01 AC 318 ms
56,984 KB
testcase_02 AC 317 ms
56,908 KB
testcase_03 AC 321 ms
57,020 KB
testcase_04 AC 310 ms
56,836 KB
testcase_05 AC 313 ms
56,948 KB
testcase_06 AC 310 ms
56,976 KB
testcase_07 AC 316 ms
56,824 KB
testcase_08 AC 307 ms
56,856 KB
testcase_09 AC 311 ms
56,796 KB
testcase_10 AC 316 ms
56,808 KB
testcase_11 AC 308 ms
56,968 KB
testcase_12 AC 306 ms
56,896 KB
testcase_13 AC 310 ms
56,936 KB
testcase_14 AC 309 ms
56,948 KB
testcase_15 AC 311 ms
56,868 KB
testcase_16 AC 318 ms
56,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fun main() {
    val (n, p) = readln().split(" ").map { it.toLong() }
    var e = 0L
    var m = n
    while (m > 0) {
        e += m / p
        m /= p
    }
    println(pow(p, e))
}

fun pow(a: Long, e: Long): Long {
    val mod = 998244353L
    if (e == 0L) return 1
    if (e == 1L) return a % mod
    val b = pow(a, e / 2)
    return if (e % 2 == 0L) {
        b * b % mod
    } else {
        (b * b % mod) * a % mod
    }
}
0