
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How To Check Whether a Number Is a Insolite Number or Not in Java?
What is Insolite Number?
An Insolite number is a number if it is divisible by both the addition of squares of each digit and the square of the whole product value of all digits.
For example, we have a number 123, first, we need to find the sum of squares of each digit (sum of square = 1^2 + 2^2 + 3^2), and then we have to multiply each digit of the given number (product = 1 x 2 x 3).
Now, we have to calculate the square value of the product (product square = (1 x 2 x 3)^2). If the given number is divisible by both the resultant values (i.e., the sum of squares and product square), then we can say that the given number is an Insolite number.
Input & Output Scenarios
Below are a few input and output scenarios that help you to check if the number is an Insolite number or not by doing mathematical calculations:
Scenario 1
Suppose we have the input number 1122112:
Input: 1122112 Output: Yes
Calculation
Sum of square of each digit = (1^2) + (1^2) + (2^2) + (2^2) + (1^2) + (1^2) + (2^2)
= 1 + 1 + 4 + 4 + 1 + 1 + 4 = 16
Square of the whole product of all digit = (1 * 1 * 2 * 2 * 1 * 1 * 2 ) ^ 2 = 64
Since the number 1122112 is completely divisible by both 16 and 64, 1122112 is an insolite number.
Scenario 2
Suppose the given number is 123123:
Input: 123123 Output: No
Calculation
Sum of square of each digit = (1^2) + (2^2) ++ (3^2) + (1^2) + (2^2) + (3^2)
= 1 + 4 + 9 + 1 + 4 + 9 = 28
Square of the whole product of all digit = (1 * 2 * 3 * 1 * 2 * 3) ^ 2 = 1296
The number 123123 is not divisible by both 28 and 1296; therefore, it is not an insolite number.
Example 1
The following example will check whether the number 1122112 is an Insolite number by dividing it by the sum of the square of each digit and the square of the whole product of this number:
import java.lang.Math; public class checkInsolite { public static void main (String[] args){ int inputNumber = 1122112; System.out.println("The given number is: " + inputNumber); int temp = inputNumber; int sum = 0; // for storing the multiplication value declare a variable int prod = 1; while (temp != 0){ int i = temp % 10; sum = sum + (int)Math.pow(i, 2); //calculate the multiplication value prod = prod * (int)Math.pow(i, 2); temp = temp / 10; } //whether both resultant values are divisible by inputNumberor not if((inputNumber % sum == 0) && (inputNumber % prod == 0)){ System.out.print("Yes! " + inputNumber + " is an Insolite Number."); } else{ System.out.print("No! " + inputNumber + " is not an Insolite Number."); } } }
The above program produces the following output:
The given number is: 1122112 Yes! 1122112 is an Insolite Number.
Example 2
In the example below, we define a method named checkInsoliteNumber(), which calculates and returns true or false based on the number 126317, divisible by the sum of the square of each digit and the square of the whole product of this number:
public class checkInsolite{ static boolean checkInsoliteNumber(int num){ int temp = num; int sum = 0; int prod = 1; while (temp != 0){ int i = temp % 10; sum = sum + i * i; prod = prod * i * i; temp = temp / 10; } //check whether both resultant values are divisible by the number or not if((num % sum == 0) && (num % prod == 0)){ return true; } else{ return false; } } public static void main (String[] args){ int inputNumber = 126317; System.out.println("The given number is: " + inputNumber); //calling the checkInsoliteNumber() method to check insolite number System.out.print("Is the number " + inputNumber + " is an Insolite number? "); System.out.println(checkInsoliteNumber(inputNumber)); } }
Following is the output of the above program:
The given number is: 126317 Is number 126317 a Insolite number? false