A disarium number is a number in which the sum of its digits, each raised to the power of its position, equals the number itself. For example, 135 is a disarium number because 11 + 32 + 53 = 1 + 9 + 125 = 135. To check a disarium number in Java, we extract the digits and add their powers.
Positions are counted from the left, starting at 1. Disarium numbers are a classic exercise for digit extraction with % and /, and they appear in school programming assignments and coding tests next to Armstrong and Harshad numbers.
The following example checks 135 by walking over its digits as characters.
String digits = "135";
int sum = IntStream.range(0, digits.length()).map(i -> (int) Math.pow(digits.charAt(i) - '0', i + 1)).sum(); // 135
boolean disarium = sum == Integer.parseInt(digits); // true
The character index i starts at 0, so the power is i + 1. We look at more examples, write the arithmetic version that works on int and long without Math.pow(), find every disarium number in a range, and compare disarium numbers with Armstrong numbers.
1. Disarium Number
A number is called disarium if the sum of its digits, powered with their respective positions, is equal to the original number. The first digit is raised to the power 1, the second to the power 2, and so on.

For example, 89, 135, 175 and 518 pass the check, whereas the powers of 134 add up to only 74.
| Number | Digit powers | Sum | Disarium |
|---|---|---|---|
| 135 | 11 + 32 + 53 | 1 + 9 + 125 = 135 | Yes |
| 89 | 81 + 92 | 8 + 81 = 89 | Yes |
| 175 | 11 + 72 + 53 | 1 + 49 + 125 = 175 | Yes |
| 518 | 51 + 12 + 83 | 5 + 1 + 512 = 518 | Yes |
| 134 | 11 + 32 + 43 | 1 + 9 + 64 = 74 | No |
Every single-digit number is disarium, because a digit raised to the power 1 is the digit itself. Beyond that, disarium numbers are rare. In base 10 there are only 20 of them, counting 0, and the set is finite, as listed in OEIS A032799.
- The numbers 0 to 9.
- The numbers 89, 135, 175, 518 and 598.
- The numbers 1306, 1676 and 2427.
- The number 2646798.
- The 20-digit number 12157692622039623539, which is larger than Long.MAX_VALUE.
The list is finite because the digit powers cannot keep up with the number. A number with m digits is at least 10m-1, while its largest possible disarium sum is 91 + 92 + … + 9m. From 23 digits on, the sum is always too small, so no disarium number has more than 22 digits.
2. Java Program to Find Disarium Number
The program reads the digits from right to left with % 10 and / 10. Because the rightmost digit has the highest position, we count the digits first and lower the power by one after each digit. Integer multiplication replaces Math.pow(), so no double rounding is involved, and the method accepts any long.
static long power(int digit, int exponent) {
long result = 1;
for (int i = 0; i < exponent; i++) {
result *= digit;
}
return result;
}
static boolean isDisarium(long originalNumber) {
if (originalNumber < 0) {
return false;
}
// Total number of digits = position of the rightmost digit
int position = Long.toString(originalNumber).length();
long sumOfDigits = 0;
long tempNum = originalNumber;
while (tempNum != 0) {
int currentDigit = (int) (tempNum % 10); // rightmost digit
sumOfDigits += power(currentDigit, position--); // power by position
tempNum = tempNum / 10;
}
// The number is disarium when the sum equals the original number
return sumOfDigits == originalNumber;
}
boolean n134 = isDisarium(134); // false
boolean n135 = isDisarium(135); // true
boolean n136 = isDisarium(136); // false
boolean n2427 = isDisarium(2427); // true
boolean n2646798 = isDisarium(2_646_798); // true
boolean negative = isDisarium(-135); // false
Negative numbers return false, since a minus sign has no position and no disarium number is negative. For a 19-digit long, the largest possible sum of digit powers is about 1.5 x 1018, which still fits in a long, so the method cannot overflow.
The left-to-right version from the intro is shorter, and it reads the positions in their natural order. It is fine for exercises, but it creates a String for every number and uses Math.pow(), which returns a double. For int values the result is exact, but in a loop over millions of numbers the integer version is the better default.
3. Printing All Disarium Numbers in a Range
Exercises often ask for all disarium numbers between 1 and some limit. A LongStream filter over the range does the job in one statement, in the same way as the IntStream filters, and it reuses isDisarium().
List<Long> upTo1000 = LongStream.rangeClosed(1, 1_000).filter(n -> isDisarium(n)).boxed().toList(); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 89, 135, 175, 518, 598]
List<Long> upTo3Million = LongStream.rangeClosed(1_000, 3_000_000).filter(n -> isDisarium(n)).boxed().toList(); // [1306, 1676, 2427, 2646798]
There are no more disarium numbers until the 20-digit one, so searching beyond 3,000,000 with a loop finds nothing for a very long time. Programs that need the complete list store the 20 known values in a constant instead of searching.
4. Checking the 20-Digit Disarium Number With BigInteger
The largest disarium number, 12157692622039623539, does not fit in a long, whose maximum is 9223372036854775807. A version based on BigInteger and the digit characters of the number handles any length.
static boolean isDisarium(BigInteger number) {
String digits = number.toString();
BigInteger sum = BigInteger.ZERO;
for (int i = 0; i < digits.length(); i++) {
BigInteger digit = BigInteger.valueOf(digits.charAt(i) - '0');
sum = sum.add(digit.pow(i + 1));
}
return sum.equals(number);
}
boolean largest = isDisarium(new BigInteger("12157692622039623539")); // true
boolean neighbour = isDisarium(new BigInteger("12157692622039623538")); // false
The overload is only needed for this one number, but it is a good check that our understanding of the definition is right.
5. Disarium Number vs Armstrong Number
Both checks raise digits to a power and compare the sum with the number. A disarium number raises each digit to its own position, while an Armstrong number raises every digit to the same power, the digit count.
| Disarium number | Armstrong number | |
|---|---|---|
| Power of each digit | Its position (1, 2, 3, …) | The number of digits |
| Example | 135 = 11 + 32 + 53 | 153 = 13 + 53 + 33 |
| Three-digit members | 135, 175, 518, 598 | 153, 370, 371, 407 |
| Count in base 10, counting 0 | 20 (finite) | 89 (finite) |
The only code difference is the exponent. The Armstrong check passes the digit count to power() for every digit, while the disarium check lowers the exponent after each digit.
static boolean isArmstrong(long n) {
int digitCount = Long.toString(n).length();
long sum = 0;
for (long t = n; t != 0; t /= 10) {
sum += power((int) (t % 10), digitCount);
}
return sum == n;
}
boolean a153 = isArmstrong(153); // true
boolean d153 = isDisarium(153); // false
boolean a135 = isArmstrong(135); // false
Digit-based checks such as the Harshad number use the same % 10 loop with a different rule for the digits, and the Java examples page groups the other number programs.
6. Disarium Number FAQs
Exam papers and coding tests ask about a few specific numbers and the size of the list more than about the code.
6.1. Is 89 a disarium number?
Yes. 81 + 92 = 8 + 81 = 89. It is the smallest disarium number with more than one digit.
6.2. Is 0 a disarium number?
Yes. The single digit 0 raised to the power 1 is 0, and OEIS A032799 lists 0 as the first term. Many exercises ask for numbers from 1, so they start the list at 1. The isDisarium(long) method in section 2 returns true for 0, because the loop does not run and the sum 0 equals the number.
6.3. How many disarium numbers are there?
There are 20 in base 10, counting 0, and the largest is 12157692622039623539. The set is finite because numbers with 23 or more digits grow faster than any sum of their digit powers.
6.4. Is 11 a disarium number?
No. 11 + 12 = 2, which is not 11. The numbers 10 to 88 contain no disarium number at all.
6.5. Why does the program count the digits first?
Because the loop reads digits from right to left, and the rightmost digit has the highest position. Knowing the digit count gives the power for the first digit read, and the program lowers it by one for each following digit.
7. Conclusion
A disarium number equals the sum of its digits raised to their positions, such as 89, 135 and 518. The arithmetic check counts the digits, reads them from right to left and lowers the power after each digit, and integer multiplication keeps it exact for every long.
Only 20 disarium numbers exist, so range searches find nothing above 2646798 until the 20-digit value, which needs BigInteger. The Armstrong check uses the same loop with one fixed exponent.
8. References
- OEIS A032799, Disarium numbers
- OEIS A005188, Armstrong (narcissistic) numbers
- BigInteger.pow() Javadoc
- LongStream Javadoc
Happy Learning !!