Untouchable Number in Java
In this section, we will learn what is an untouchable number and also create Java programs to check if the given number is an untouchable number or not. The untouchable number program is frequently asked in Java coding interviews and academics.
A number N is called an untouchable number if the number is not the sum of the proper divisor of any positive number. It is also called nonaliquot numbers. It is an OEIS sequence A005114.
In other words, we can say that it is a positive integer that cannot be expressed as the sum of all the proper divisors of any positive integer including the untouchable number itself.
Let's understand it through an example.
Untouchable Number Example
The number 4 is not an untouchable number because it is equal to the sum of the proper divisors of 9 i.e., 1+3 = 4.
The number 5 is an untouchable number because it is not equal to the sum of the proper divisors of any positive number. It means to say that there is only a way to write 5 i.e. 1+4. The number 4 divides a number, also 2 does the same. So, 1+4 cannot be the sum of any proper divisors.
Some other untouchable numbers are 2, 5, 52, 88, 96, 120, 124, 146, 162, 188, 206, 210, 216, 238, 246, 248, 262, 268, 276, 288, 290, 292, 304, 306, 322, 324, 326, 336, 342, 372, 406, 408, 426, 430, 448, 472, 474, 498, 516, 518, 520, 530, 540, 552, 556, 562, 576, 584, 612, 624, 626, 628, 658.
We observe that the number 5 is the only odd untouchable number.
Steps to Find Untouchable Number
Let's implement the above steps in a Java program.
Untouchable Number Java Program
In the following program, we find the sum of the proper divisors of the number N and check whether the sum is equal to N or not. If the sum is equal to N, the given number N is an untouchable number. Else, not an untouchable number.
Enter the number: 5 The given number is an untouchable number.
Enter the number: 36 The given number is not an untouchable number.