// Strong numbers are the numbers that the sum of factorial of its digits
// is equal to the original number
// 145 is a strong number: 1 + 24 + 120 = 145
import Foundation
func factorial(_ n: Int) -> Int {
var fact = 1
for i in 1...n {
fact *= i
}
return fact
}
func main() {
var n = 145, reminder: Int, sum = 0, tmp: Int
tmp = n
while n != 0 {
reminder = n % 10
sum += factorial(reminder)
n /= 10
}
if sum == tmp {
print("\(tmp) is a strong number")
} else {
print("\(tmp) is not a strong number")
}
}
main()
/*
run:
145 is a strong number
*/