Javatpoint Logo
Javatpoint Logo

Sublime Number in Java

In this section, we will learn what is a sublime number and also create Java programs to check if the given number is a sublime number or not. The sublime number program is frequently asked in Java coding interviews and academics.

Sublime Number

A natural number N is called sublime number if both the sum of its divisors and the number of its divisors or factors (including itself) are perfect numbers (the number whose sum of factors is equal to the number itself). It is an OEIS sequence A081357.

There are only two sublime numbers i.e. 12 that is the smallest sublime number and the second sublime number is 76 digits long number i.e. 6,086,555,670,238,378,989,670,371,734,243,169,622,657,830,773,351,885,970,528,324,860,512,791,691,264.

Let's understand it through an example.

Sublime Number Example

Let's see how 12 is a sublime number.

The number of factors or divisors of 12 are 6 i.e. 1, 2, 3, 4, 6, and 12

The sum of divisors is: 1 + 2 + 3 + 4 + 6 + 12 = 28

Both 6 and 28 are perfect numbers. Hence, 12 is a sublime number.

Steps to Find Sublime Number

  1. Read or initialize a number n.
  2. Find the divisors of the given number (n).
  3. Count the total number of divisors of the given number (n) and store it in a variable (count).
  4. Sum up the divisors, and store the result in a variable (sum).
  5. At last, check count and sum are perfect numbers or not.
  6. If both are perfect numbers, the given number (n) is a sublime number.
  7. Else, not a sublime number.

Therefore, we have to implement two main logics:

1. Find and Count Divisors of a Number Logic

2. Perfect Number Logic

Let's implement the above logic in a Java program and check whether the given number is sublime or not.

Subline Number Java Program

Output 1:

Enter the number: 12
12 is a sublime number.

Output 2:

Enter the number: 346587
346587 is not a sublime number.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA