×

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[0] = prime[1] = 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.


Related Topics

Java Wrapper Class

Wrapper class in Java encapsulates a primitive type within an object. In other words, it is a unique mechanism of Java to convert primitive type in to object and object into primitive type....

3 minutes read.

Java Lambda foreach

Before understanding lamda foreach, one must know about foreach loop in Java. foreach loop in Java Since J2SE 5.0, there has been a for-each loop in Java, also known as an extended...

4 minutes read.

Java File

Java file class implements the concept of file handling. It has several methods, such as deleting, creating, reading, and updating files. This class allows java users to perform various operations...

5 minutes read.

Java vs Node.js

Java: Java is an object oriented programming language. It is also known as multi threaded language. It was designed by James gosling in the year 1995. We can also say that...

4 minutes read.

Graphics Program in Java

Graphics Program in Java The graphics program in Java is part of the Swing program in Java. In this section, we will learn about the implementation of custom graphics using some...

6 minutes read.

How to find the length of an Array in Java

Arrays: An array is a sort of container object that stores constant quantities of values of a single type in one memory area. A finite number of items must all be...

3 minutes read.

Java Class Methods

Methods called on a class rather than a specific object instance are known as class methods. The static modifier guarantees uniform implementation across all instances of the class. Syntax public class NameOfClass...

3 minutes read.

Difference between next() and nextline() in Java

One of the simplest methods for receiving input of the basic data types, also including int, double, and strings, in Java, is to use the Scanner class, which is part...

3 minutes read.

Minimum Number of Taps to Open to Water a Garden in Java

Problem Statement The issue is that a gardener wants to water a (single-dimensional) garden using the fewest possible tap openings. The goal is to determine the minimum necessary taps to be...

8 minutes read.

How to run java program in ubuntu

To run the java programming in ubuntu, we need to follow several steps: Let's see the process. Step1: Install the Java compiler or JDK to the system. To run the java program, we...

3 minutes read.

Best Practices to use String Class in Java

Use String Builder or String Buffer for String concatenation in place of + operator.Compare two strings by equals( ) method instead == operator.Call .equals( ) method on a known String...

3 minutes read.

Constructor Overloading in Java

In Java, constructors can be overloaded just like methods. The idea of having multiple constructors with various parameter sets so that each function Object()  can carry out a particular task...

3 minutes read.

Traverse through HashMap in Java

In this tutorial, we will discuss traversing through HashMap in Java Introduction: HashMap<Key, Value> is a part of the java collection implemented from the java 1.2 version. HashMap is written as HashMap<K,...

4 minutes read.

Method Overloading In Java

If the same class consists of different methods with the same name and the methods can vary by different number of parameters then it is known as Method Overloading. Method...

2 minutes read.

Java Create File

A File is a hypothetical way, which has no genuine presence. It is very much like while "using" that File that the major real activity of putting away something in...

5 minutes read.

Java Integer numberOfLeadingZeros() method

The numberOfLeadingZeros()  method of Java Integer class returns the total number of zero bits preceding the highest-order one-bit in the 2’s complement binary representation of the specified int value.  Syntax public static...

1 minute read.

Vigesimal in Java

A number system with a base of 20 is known as the vigesimal in Java. A base-20 (base-score) numeric system, often known as a vigesimal system, is centered on the twenty...

4 minutes read.

Java Math sinh() Method

The sinh() method of Java Math class returns the hyperbolic sine of the specified double value. Syntax: public static double sinh(double x) Parameters: The parameter ‘a’ represents the number whose hyperbolic sine is to...

2 minutes read.

Java StringWriter Class

The StringWriter class is a character stream in which it is used to store the output consisting of characters into the string buffer. Upon collecting output into a string buffer,...

3 minutes read.

Java calculate age

In this section, we will create a Java program that calculates age from the given date of birth or current date. In order to get the date of birth from the current...

6 minutes read.