Check Disarium Number in Python

Beginner
⏱️ 9 min read
📚 Updated: May 2026
🎯 2 Code Examples
Digit sums

What you’ll learn

  • The Disarium rule in simple terms: position-based powers from left to right.
  • How to implement it using easy digit peeling with % 10 and // 10.
  • Single check, range scan, live preview, and common mistakes.

Overview

A positive number is Disarium if each digit raised to its left-to-right position adds back to the same number. Example: 89 = 8^1 + 9^2.

Two programs

Single-number check and 1-100 scan.

Live preview

Try numbers instantly in browser.

Common confusion

Different from Armstrong numbers.

Prerequisites

Loops, modulo, integer division, and basic functions in Python.

  • Use % 10 to read the last digit and // 10 to remove it.
  • Use pow or ** for integer exponentiation.

What is a Disarium number?

If digits are d1 d2 ... dk from left, check whether d1^1 + d2^2 + ... + dk^k equals the number.

Example: 135 = 1^1 + 3^2 + 5^3 so it is Disarium.

898^1 + 9^2
1351^1 + 3^2 + 5^3
10not Disarium

Formal sum

For positive n with k digits, Disarium means n = sum(d_i ^ i) where position i starts from 1 at the leftmost digit.

89

8^1 + 9^2 = 8 + 81 = 89

Intuition

89Disarium
Sum
8 + 81
10Not
Sum
1 + 0 = 1

Takeaway: the rightmost digit always gets the highest exponent.

Live preview

Positive integers only, within JavaScript safe range.

Live result
Press "Check" to evaluate.

Algorithm

Goal: check if positive n equals its position-power digit sum.

Count digits

Set exponent to total digit count.

Peel and add

Take last digit, raise to current exponent, add to sum, decrease exponent.

Compare sum

If sum equals original number, it is Disarium.

📜 Pseudocode

Pseudocode
function is_disarium(n):  // n > 0
    k = number_of_digits(n)
    sum = 0
    pos = k
    while n > 0:
        digit = n mod 10
        sum += digit ^ pos
        pos -= 1
        n = floor(n / 10)
    return sum == original_n
1

Single value check (89)

Direct and interview-friendly implementation for one input value.

python
def is_disarium(number: int) -> bool:
    if number <= 0:
        return False

    original = number
    digits = len(str(number))
    total = 0

    while number > 0:
        digit = number % 10
        total += digit ** digits
        digits -= 1
        number //= 10

    return total == original


n = 89
if is_disarium(n):
    print(f"{n} is a Disarium number.")
else:
    print(f"{n} is not a Disarium number.")

Explanation

The first peeled digit is the rightmost one, so we start exponent from full digit count and decrease each step.

2

Disarium numbers from 1 to 100

Prints all Disarium numbers in this beginner range.

python
def is_disarium(num: int) -> bool:
    if num <= 0:
        return False
    original = num
    digits = len(str(num))
    total = 0

    while num > 0:
        digit = num % 10
        total += digit ** digits
        digits -= 1
        num //= 10

    return total == original


print("Disarium numbers in the range 1 to 100:")
for i in range(1, 101):
    if is_disarium(i):
        print(i, end=" ")

Explanation

All one-digit positive numbers are Disarium. In two digits up to 100, only 89 matches.

Optimization

Cache powers. Precompute digit powers for each position when scanning large ranges.

Early pruning. Use rough upper bounds to skip impossible ranges.

Interview: clearly state left-position powers and Armstrong difference.

❓ FAQ

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.
Using % 10 and // 10 is simple. To keep powers correct, we start exponent from total digit count and decrease it each step.
Yes. Python integer arithmetic is exact for big integers, so ** is safe for this kind of interview program.
Most common definitions focus on positive numbers. In this page we check positive integers only.
Yes for 1 to 9, because d^1 = d.
For d digits, checking one number is O(d^2) in the straightforward version with repeated powers, and can be improved with caching.

🔄 Input / output examples

Change input values in the first example or range limits in the second one.

nDisarium?Check
89Yes8^1 + 9^2 = 89
135Yes1^1 + 3^2 + 5^3 = 135
10No1^1 + 0^2 = 1
7Yes7^1 = 7

Edge cases and pitfalls

Most lists use positive numbers only; be explicit about zero and negatives.

Zero

n = 0

Commonly excluded by definition; this page checks positive numbers only.

Position

Left-to-right count

Do not use right-to-left positions directly without adjusting exponent order.

Armstrong

Different formula

Armstrong uses fixed exponent equal to digit count for all digits.

Large range

Power growth

Use caching or careful bounds if scanning very large intervals.

⏱️ Time and space complexity

OperationTimeExtra space
Single check (basic)O(d^2)O(1)
Single check (cached powers)O(d)O(d)
Range [1..N]About O(N * d^2)O(1)

Summary

  • Rule: digit powers depend on left position.
  • Code: peel from right, decrease exponent each step.
  • Remember: Disarium is different from Armstrong.
Did you know?

Besides 89, 135 is a classic Disarium number because 11 + 32 + 53 = 135. Every one-digit positive number 1 to 9 is Disarium.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful