A Disarium number is a number in which the sum of its digits, each raised to the power of its position, equals the original number.
š” Example of a Disarium Number:
Take 89:
\[ 8^1 + 9^2 = 8 + 81 = 89 \]Since the sum equals the original number, 89 is a Disarium number.
In this tutorial, we will write a Python program to check whether a given number is a Disarium number or not.
Python Program to Check Disarium Number
# Function to check if a number is Disarium def is_disarium(num): num_str = str(num) length = len(num_str) sum_digits = sum(int(digit) ** (index + 1) for index, digit in enumerate(num_str)) return sum_digits == num # Taking user input number = int(input("Enter a number: ")) # Checking and displaying the result if is_disarium(number): print(f"{number} is a Disarium number.") else: print(f"{number} is not a Disarium number.")
Output
Enter a number: 89 89 is a Disarium number.
ā Test Cases:
Number | Calculation | Disarium? |
---|---|---|
89 | 81 + 92 = 8 + 81 = 89 | ā Yes |
135 | 11 + 32 + 53 = 1 + 9 + 125 = 135 | ā Yes |
123 | 11 + 22 + 33 = 1 + 4 + 27 = 32 | ā No |