A positive integer is a Disarium number when the sum of its digits, each raised to the power of its left-to-right position (starting at 1), equals the number itself.
Four clear steps — then pick a right-to-left peel or a left-to-right digit string.
Require a positive integer (n > 0).
Count the digits (or convert to a string).
Raise each digit to its position power and add the results.
Compare the sum with the original n.
Method
Idea
Time
Best for
Right-to-left peel
Start power at digit count; decrease while peeling
O(d²)
Interviews without strings
Digit string
Index i maps to power i + 1
O(d²)
Clear left-to-right reasoning
Pseudocode
Pseudocode
function IsDisarium(n):
if n <= 0: return false
digits = countDigits(n)
sum = 0
temp = n
power = digits
while temp > 0:
digit = temp mod 10
sum = sum + digit ^ power
power = power - 1
temp = temp / 10
return sum == n
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
Position
Leftmost digit has power 1
vs Armstrong
Armstrong uses one shared exponent (digit count)
One digit
1–9 are all Disarium
Classic checks
89, 135
Power
Use digit ** power (int), not math.pow
Zero / negatives
Treat as not Disarium in this tutorial
Try it
Live Preview
Enter a positive integer to see each digitposition term and the final check.
Positive integers only. Tap a chip or type a value.
Result
n = 135
1^1 + 3^2 + 5^3 = 1 + 9 + 125 = 135
135 is a Disarium number
Trace
Worked Walkthrough — n = 135
Three digits → powers 1, 2, and 3 from left to right.
Calculation
Digits: 1, 3, 5 (count = 3)
1¹ = 1
3² = 9
5³ = 125
Sum = 1 + 9 + 125 = 135
135 == 135 → Disarium
Right-to-left peel (same powers):
peel 5 with power 3 → 125
peel 3 with power 2 → 9
peel 1 with power 1 → 1
Code
Python Programs
Start with the integer peel so you can explain every power without strings. Then use a digit string when left-to-right indexing feels clearer.
Example 1 — Right-to-Left Peel
Count digits, then peel from the right while decreasing the position power.
python
def count_digits(n: int) -> int:
count = 0
while n > 0:
count += 1
n //= 10
return count
def is_disarium(n: int) -> bool:
if n <= 0:
return False
power = count_digits(n)
total = 0
temp = n
while temp > 0:
digit = temp % 10
total += digit ** power
power -= 1
temp //= 10
return total == n
number = 135
if is_disarium(number):
print(f"{number} is Disarium")
else:
print(f"{number} is not Disarium")
Output
135 is Disarium
How It Works
count_digits finds how many positions exist — that becomes the starting power.
Reject non-positive inputs; this page defines Disarium for positive integers only.
Each temp % 10 peels the next rightmost digit; power -= 1 keeps positions correct.
digit ** power stays an exact int for nonnegative integers.
Compare total == n. For 135: 5³ + 3² + 1¹ = 125 + 9 + 1 = 135.
Example 2 — Digit String
Convert to a string so index i maps directly to power i + 1.
python
def is_disarium(n: int) -> bool:
if n <= 0:
return False
s = str(n)
total = 0
for i, ch in enumerate(s):
digit = int(ch)
power = i + 1
total += digit ** power
return total == n
print(is_disarium(89)) # True
print(is_disarium(90)) # False
print(is_disarium(135)) # True
Output
True
False
True
How It Works
str(n) writes digits in left-to-right order.
enumerate gives index 0 for position 1, so power is always i + 1.
int(ch) converts a digit character to an integer.
Same ** power keeps results exact integers.
Answers match Example 1; pick the style that is easier to explain in the interview.
Edge Cases & Pitfalls
Check these before calling the solution done.
1–9
Single digits
All of 1 through 9 pass because d¹ = d.
Powers
Not all cubes
Each digit gets its own position power — unlike Armstrong.
math.pow
Prefer **
math.pow returns float; use digit ** power for exact ints.
≤ 0
Not Disarium here
This tutorial requires a positive integer.
Analysis
Time and Space Complexity
Program
Time
Extra space
Right-to-left peel
O(d²)
O(1)
Digit string
O(d²)
O(d) for the string
Here d is the digit count. Each power costs up to O(d) multiplies, and there are d digits.
Remember
Key Takeaways
Definition: digitposition sum equals n (positions from the left).
Peel trick: start power at digit count and decrease while peeling right.
vs Armstrong: Disarium uses different powers per digit.
Test set: 7 → yes; 89 → yes; 135 → yes; 90 → no.
One line: raise each digit to its left-to-right position and compare the sum with n.
Frequently Asked Questions
A positive integer n is Disarium if the sum of its digits, each raised to the power of its left-to-right position (starting at 1), equals n. Example: 89 = 8¹ + 9².
Armstrong raises every digit to the same power (the digit count). Disarium raises each digit to its own position index from the left.
n % 10 and n // 10 are simple. Start the exponent at the digit count and decrease it so powers still match left-to-right positions.
Yes for nonnegative integer bases and exponents: digit ** power stays an exact int in Python. Prefer that over math.pow, which returns float.
Yes for 1 through 9, because d¹ = d. Zero is usually excluded when the definition requires a positive integer.
For d digits, a straightforward check with integer powers is O(d²) time and O(1) extra space for the peel method.