← Coding round practice

Factorial of a Number

EasyNumbers & Math

The problem

Compute the factorial of a number n (the product of all integers from 1 to n).

Sample input

5

Sample output

120
Show the solution · 8 languages
fun factorial(n: Int): Long {
    var result = 1L
    for (i in 2..n) result *= i
    return result
}

fun main() {
    println(factorial(5))
}