krishnamurthy number it is also known as peterson number a krishnamurthy number is a number whose sum of the factorial of the digits equals to the original number itself for example 145 1 4 5 so 145 is a krishnamurthy number factorial3 6 factorial0 1 factorial5 120 krishnamurthy145 true krishnamurthy240 false krishnamurthy1 true factorial 3 6 factorial 0 1 factorial 5 120 krishnamurthy 145 true krishnamurthy 240 false krishnamurthy 1 true
def factorial(digit: int) -> int:
    

    return 1 if digit in (0, 1) else (digit * factorial(digit - 1))


def krishnamurthy(number: int) -> bool:
    

    fact_sum = 0
    duplicate = number
    while duplicate > 0:
        duplicate, digit = divmod(duplicate, 10)
        fact_sum += factorial(digit)
    return fact_sum == number


if __name__ == "__main__":
    print("Program to check whether a number is a Krisnamurthy Number or not.")
    number = int(input("Enter number: ").strip())
    print(
        f"{number} is {'' if krishnamurthy(number) else 'not '}a Krishnamurthy Number."
    )