What is an automorphic number?
A number is called an automorphic number if and only if the square of the given number ends with the same number itself. For example, 25, 76 are automorphic numbers because their square is 625 and 5776, respectively and the last two digits of the square represent the number itself. Some other automorphic numbers are 5, 6, 36, 890625, etc.
#Output
#67
#68
#69
A number is called an automorphic number if and only if the square of the given number ends with the same number itself. For example, 25, 76 are automorphic numbers because their square is 625 and 5776, respectively and the last two digits of the square represent the number itself. Some other automorphic numbers are 5, 6, 36, 890625, etc.
#Output
#67
#68
#69
A simple solution would be to perform a counting sort. We count the total number of 0’s, 1’s, and 2’s and then put them in the array in their correct order. The time complexity of this solution is O(n), where n is the size of the input. However, this requires two traversals of the array.
#Data_structure
#Data_structure
Java
A simple solution would be to perform a counting sort. We count the total number of 0’s, 1’s, and 2’s and then put them in the array in their correct order. The time complexity of this solution is O(n), where n is the size of the input. However, this requires…
We can rearrange the array in a single traversal using an alternative linear-time partition routine that separates the values into three groups:
The values less than the pivot,
The values equal to the pivot, and
The values greater than the pivot.
#Data_structure
#Source_code
#70
The values less than the pivot,
The values equal to the pivot, and
The values greater than the pivot.
#Data_structure
#Source_code
#70
Peterson Number Java Program
In the following program, we have taken an array of factorial to quickly find the factorial. You can use the logic also.
#Source_code
#71
In the following program, we have taken an array of factorial to quickly find the factorial. You can use the logic also.
#Source_code
#71
Java
Peterson Number Java Program In the following program, we have taken an array of factorial to quickly find the factorial. You can use the logic also. #Source_code #71
Steps to Find Peterson Number
* Read or initialize a number (n).
* Find the last digit (d) of the given number.
* Find the factorial (fact) of the digit.
* Add the factorial (fact) to a variable
* Repeat steps 2 to 4 until the given number becomes 0.
* Compare the sum with n. If both are equal, the given number is Peterson, else not.
#Output
#71
* Read or initialize a number (n).
* Find the last digit (d) of the given number.
* Find the factorial (fact) of the digit.
* Add the factorial (fact) to a variable
* Repeat steps 2 to 4 until the given number becomes 0.
* Compare the sum with n. If both are equal, the given number is Peterson, else not.
#Output
#71
Sunny Number
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
Let's understand it through an example.
#Source_code
#72
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
Let's understand it through an example.
#Source_code
#72
Java
Sunny Number A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square. Let's understand it through an example. #Source_code #72
Steps to Find Sunny Number
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
Let's implement the above steps in a Java program.
#Output
#72
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
Let's implement the above steps in a Java program.
#Output
#72
Sunny Number
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
#Source_code
#73
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
#Source_code
#73
Java
Sunny Number A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square. #Source_code #73
Steps to Find Sunny Number
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
#Output
#73
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
#Output
#73
Find the Duplicate element in a limited range array
Given a limited range array of size n containing elements between 1 and n-1 with one element repeating, find the duplicate number in it without using any extra space.
#Data_structure
Given a limited range array of size n containing elements between 1 and n-1 with one element repeating, find the duplicate number in it without using any extra space.
#Data_structure
Fascinating Number Java Program
The base condition to check whether a number is fascinating or not is that the number must have at least 3 or more than three digits.
#Source_code
#75
The base condition to check whether a number is fascinating or not is that the number must have at least 3 or more than three digits.
#Source_code
#75