// Strong numbers are the numbers that the sum of the factorial of its digits
// is equal to the original number
// 145 is a strong number: 1 + 24 + 120 = 145
object StrongNumber {
def calculateFactorial(number: Int): Int = {
var fact = 1
for (i <- 1 to number) {
fact *= i
}
fact
}
def main(args: Array[String]): Unit = {
val number = 145
var sum = 0
var n = number
while (n != 0) {
val remainder = n % 10
val fact = calculateFactorial(remainder)
n = n / 10
sum += fact
}
if (sum == number) {
println("Strong Number")
} else {
println("Not Strong Number")
}
}
}
/*
run:
Strong Number
*/