×

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

LCM Program in Java

LCM Program in Java The LCM program in Java outputs the LCM of the given numbers. In Arithmetic, the lowest common multiple, least common multiple or smallest common multiple of the...

6 minutes read.

Java Integer doubleValue() method

The doubleValue() method of Integer class returns a double value for this Integer after a widening primitive conversion. Syntax public double doubleValue() Parameters NA Specified by This method is specified by doubleValue in class Number Return Value This...

1 minute read.

Array and String with Examples in Java

Array in Java: An array in Java is a group of variables with similar types that have a common name. The arrays used in Java differ from those used in C/C++. Key...

6 minutes read.

Java this keyword

This Keyword in Java This keyword can be used in many different ways in Java. This is a reference variable in Java that points to the active object. In Java, the...

8 minutes read.

Java Strings

String class is the most used class in Java programming language. The string is the sequence of characters, which is treated as objects in Java. Creating String objects We create String objects...

5 minutes read.

Java Keywords

Java Keywords The particular words which are used in java programming language that act like a key or important words to write a code are called java keywords. Java Keywords are...

4 minutes read.

Java Integer toUnsignedLong() method

The toUnsignedLong() method of Java Integer class returns a long value by simply converting the given argument to long after an unsigned conversion. Syntax public static long toUnsignedLong (int  x) Parameters The parameter ‘x’...

1 minute read.

Magnanimous Number in java

Magnanimous Number When the left and right halves of a majestic number are combined, the result is invariably a prime number, which must have at least two digits. The number's left...

3 minutes read.

Short Circuit Logical Operators in Java

When there are two or more relational expressions in a decision-making statement, logical operators are utilized to combine them. The logical operators short circuit and not-short circuit fall into two...

5 minutes read.

Java Database Connectivity with MySQL

In this tutorial, we will learn how to connect Database with MySQL in Java. 5 Steps to Connect to the Database in Java Load the driver (or) Register the driver classEstablish a...

4 minutes read.

Java Rename File

Renaming a file is the process of changing its name. Using the renameTo() function of the Java File class, renaming operations are possible. A file can be renamed using Java's renameTo()...

3 minutes read.

String Manipulation in Java

String Manipulation in Java In Java, string manipulation is a common task performed by programmer. Java String class provides many built-in functions that are used to manipulate string. The manipulation of...

4 minutes read.

Convert JSON File to String in Java

Before understanding the conversion of JSON file to string, one must know about JSON. What is JSON? JSON stands for JavaScript Object Notation. It is an open standard format lightweight, text-based, and...

3 minutes read.

Java Heap Space Out of Memory Error

This error is called an "out of memory" error, which indicates that the JVM cannot allocate an object in memory from the heap. Hence the java.lang.out of memory error, describing...

2 minutes read.

Java Enum

Enumerations are used in programming languages to represent collections of named constants. For instance, the four suits in a deck of playing cards might represent four iterators named Club, Diamond,...

3 minutes read.

Java.lang.Exception.NoRunnableMethods

In Programming language, the java lang unexpected no precompiled methods error generally refers to a Junit exception that happens whenever Junit is incapable of locate the precompiled test methods. When...

4 minutes read.

Java Project Ideas

When it comes to constructing projects, Java is regarded as one of the best languages and is also one of the most paid. Java excels in any application, whether it...

10 minutes read.

Read the XLSX file in Java

Excel files contain cells; reading an excel file in Java differs from reading a word file. JDK doesn't have a direct API that can read or write Word or Excel...

3 minutes read.

User Defined Custom Exceptions in Java

In this tutorial, we will discuss user-defined custom exceptions with examples. Introduction In Java, we have proactively characterised, Exception classes, for example, ArithmeticException, NullPointerException, ArrayoutOfBound and so on. These built-in exceptions are...

3 minutes read.

How to Solve the Deprecated Error in Java?

Deprecated Java methods should not be used because they are deprecated (often, there are better, more modern alternatives). API update. Until now, Java has kept everything backward compatible and never...

3 minutes read.