Learn to write a simple java program to verify if a given number is **deficient number** or not. The value `2n − σ(n)`

is called the number’s **deficiency**.

## 1. what is a deficient number

The deficient number can be defined as the number for which the sum of the proper divisors is lesser than the number itself.

As an example, consider the number 21. Its proper divisors are 1, 3 and 7, and their sum is 11. Because 11 is less than 21, the number 21 is deficient.

Its deficiency is `2 × 21 − 32 = 10`

.

Since the aliquot sums of prime numbers equal 1, all prime numbers are deficient. Similarly, all proper divisors of deficient or perfect numbers are deficient.

The first few deficient numbers are:

1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 21, 22, 23, 25, 26, 27, 29, 31, 32, 33 …

## 2. Java Program to find deficient number

public class Main { static int divsum(int n) { int sum = 0; for (int i = 1; i <= (Math.sqrt(n)); i++) { if (n % i == 0) { if (n / i == i) { sum = sum + i; } else { sum = sum + i; sum = sum + (n / i); } } } return sum; } static boolean isDeficientNumber(int n) { return (divsum(n) < (2 * n)); } public static void main(String args[]) { System.out.println("21 is deficient number : " + isDeficientNumber(21)); System.out.println("20 is deficient number : " + isDeficientNumber(20)); } }

Program output.

21 is deficient number : true 20 is deficient number : false

Happy Learning !!

Ref : Wikipedia

## Leave a Reply