Given two numbers a and b and the task is to check whether the concatenation of a and b is a perfect square or not.
Input: a = 1, b = 21
121 = 11 × 11, is a perfect square.
Input: a = 100, b = 100
100100 is not a perfect square.
Approach: Initialize the number as strings initially and concatenate them. Convert the string to a number using Integer.valueOf() function. Once the string has been converted to a number, check if the number is a perfect square or not.
Below is the implementation of the above approach.
# Python 3 program to check if the
# concatenation of two numbers
# is a perfect square or not
# Function to check if the concatenation
# is a perfect square
def checkSquare(s1, s2):
# Function to convert concatenation of
# strings to a number
c = int(s1 + s2)
# square root of number
d = math.sqrt(c)
# check if it is a perfect square
if (d * d == c) :
# Driver Code
if __name__ == “__main__”:
s1 = “12”
s2 = “1”
# This code is contributed by ita_c
- Find the Next perfect square greater than a given number
- Perfect Square String
- Closest perfect square and its distance
- Almost Perfect Number
- Difference between sum of the squares of first n natural numbers and square of sum
- Print the given 3 string after modifying and concatenating
- N-th number which is both a square and a cube
- Solid square inside a hollow square | Pattern
- Program to print Square inside a Square
- Check if two numbers are co-prime or not
- Java Program for How to check if a given number is Fibonacci number?
- Check if a number has same number of set and unset bits
- Program to check whether the given number is Buzz Number or not
- Check Whether a number is Duck Number or not
- Check if a number is a Krishnamurthy Number or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.