# Brilliant Number in Java

It is a number N that is made up of two prime numbers that have the same number of digits and is called a brilliant number.

Several/Some of the brilliant Numbers include/as follows:

4, 6, 9, 10, 14, 15, 21, 25, 35, 49….

Let us check if a number is a brilliant number or not.?

The result of two prime numbers with the same number of digits is N.

Now let us take a number, and we have found the prime numbers for them and multiply them, and the prime numbers should have two digits.

If the above condition is possible, then we say that a number is a brilliant number.

Otherwise, the number is not a brilliant number.

Let n be the number =1711

Check when we multiply the two prime numbers of the same digit like ([2,3,5,7], [13,17,19,11……...]).

Now, 1711= 29*59.

Here 29 and 59 both are prime numbers and are with number of digits two(2).

Let us check for another example that is n=16.

No there is no possibility of prime numbers that are multiplied to get our original value.

### The basic and simple approach

The goal is to use the Sieve of Eratosthenes to determine all the primes less than or equal to the specified number N. Once we have an array that contains all prime numbers, we can search through it to locate a pair that has a specific product. Using the Sieve Eratosthenes, we will locate two prime numbers with the provided product and determine whether or not they have the same number of digits.

Example:

Let’s implement the above strategy in below code:

``````// by using java we can implement this brilliant number code
import java.util.*;
import java.io.*;
public class Brilliantnumber
{

// let us create a function that generate all the possible primes
// the prime numbers are less than the given input value
static void SieveEratosthenes (int a , boolean prime[])
{
// Set the value of true for each entry in the boolean array.If i is not a prime, a value in the expression isPrime[i] will ultimately be false.
prime = prime = false;
for (int i = 2; i <= a; i++)
{
prime[i] = true;
}

for (int j = 2; j * j <= a; j++)
{

//When isPrime[j] remains unchanged, it is a prime.
if (prime[j] == true)
{

// all the multiples of j are to be updated
for (int i = j * 2; i <= a; i += j)
{
prime[i] = false;
}
}
}
}

// let create a function that should return the number of digits in a number.
static int count(int a)
{
int coun = 0;
while (a != 0)
{
a = a / 10;
++coun;
}
return coun;
}

// let us create a function to check the number is a brilliant number or not;
static boolean brilliant(int a)
{
int flag = 0;

// all the primes are generated using the above mentioned
boolean prime[] = new boolean[a + 1];
SieveEratosthenes(a, prime);

// find all possible pairs by travesing
for (int i = 2; i < a; i++)
{
int b = a / i;

if (prime[i] &&
prime[b] && (b * i) == a)
{
if (count(i) == count(b))
return true;
}
}
return false;
}

// Main code
public static void main (String[] args)
{
// the input value
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();

// call thefunctions
if (brilliant(a))
System.out.print("Yes it is a brilliant number");
else
System.out.print("No it is not a brilliant number");
}
}
``````

Output:

``````cd /home/cg/root/636d195b9e10a
1711
Yes it is a brilliant number
1211
No it is not a brilliant number
``````

## Conclusion

Peter Wallrodt is credited for creating the term "brilliant number." The phrase describes a positive integer that contains exactly two prime factors that are multiplied to get a positive and original value and both of which have the same number of digits. For instance, the number 3569 is a brilliant number because it only has the two elements 43 and 83, both of which are two digits and when they are multiplied it will give the 3569. Another illustration is the number 83779, which has the factors of two three-digit numbers 421 and 199 when they are multiplied it will give you 83779.