Javatpoint Logo
Javatpoint Logo

Economical Number in Java

In Java, number programs such as Armstrong number, Prime number, and Palindrome number are frequently asked by the interviewer. Unlike other number programs, the Economical number is not frequently asked by the interviewers.

An economical number is a number whose number of digits in the prime factorization with their powers is less than the number of digits of the original number. Let's take some examples of economical numbers:

  1. The number 125 is an economical number because its prime factorization is 5^3, and the total number of digits is 2, including power which is less than the number of digits of the original number.
  2. The number 128 is not an economical number because its prime factorization is (2^2 * 3^3). Here, the total number of digits with the power is 4, which is greater than the number of digits of the original number.
  3. The number 625 is an economical number because its prime factorization is 5^5. Here, the total number of digits with the power is 2, which is less than the number of digits of the original number.

Steps to check Economical number

These are the following steps to check whether the number is Economical or not:

  1. In the first step, we will find the primes upto 10^6.
  2. Find the total number of digits in the original number.
  3. Find all prime factors of the original number, and for each prime factor, we find the number of digits and count the highest power of it that divides the original number and calculate the sum of both of them.
  4. If the number of digits in the prime factors is less than the total number of digits in the original number, return true.

Let's implement the code to get all the Economical numbers in a certain range.

EconomicalNumber.java

Output:

Economical Number in Java





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA