結果

問題 No.500 階乗電卓
ユーザー 👑 箱
提出日時 2021-01-10 20:20:23
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 13,338 ms
コンパイル使用メモリ 436,744 KB
実行使用メモリ 55,364 KB
最終ジャッジ日時 2024-05-01 06:28:07
合計ジャッジ時間 22,468 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 332 ms
55,144 KB
testcase_01 AC 346 ms
55,320 KB
testcase_02 AC 339 ms
55,180 KB
testcase_03 AC 343 ms
55,184 KB
testcase_04 AC 296 ms
54,288 KB
testcase_05 AC 293 ms
54,360 KB
testcase_06 AC 337 ms
55,088 KB
testcase_07 AC 290 ms
54,364 KB
testcase_08 AC 291 ms
54,268 KB
testcase_09 AC 281 ms
54,304 KB
testcase_10 AC 280 ms
54,256 KB
testcase_11 AC 335 ms
55,284 KB
testcase_12 AC 340 ms
55,076 KB
testcase_13 AC 332 ms
55,212 KB
testcase_14 AC 339 ms
55,088 KB
testcase_15 AC 337 ms
55,060 KB
testcase_16 AC 347 ms
55,192 KB
testcase_17 AC 344 ms
55,364 KB
testcase_18 AC 341 ms
55,196 KB
testcase_19 AC 341 ms
55,168 KB
testcase_20 AC 336 ms
55,260 KB
testcase_21 AC 343 ms
55,124 KB
testcase_22 AC 352 ms
55,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextLong()
    var fac = 1L
    val lim = 1000000000000
    var over = false
    for (i in 1..n) {
        fac *= i
        if (fac >= lim) over = true
        fac %= lim
        if (fac == 0L) break
    }
    if (!over) {
        println(fac)
    } else {
        println("%012d".format(fac))
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve()
    writer.flush()
}

// 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