Write a program For example, if the given numbers are M is 4 and N is 16, the perfect squares from 4 to 16 are 4(2 * 2), 9(3 * 3), and 16(4 * 4), as the first perfect square is 4. So the output should be 4.
Else print No perfect Square
import math
line = input()
words = line.split()
if len(words) > 1:
M = int(words[0])
N = int(words[1])
else:
M = int(line)
N = int(input())
x = int(math.sqrt(M))
if x*x == M:
print(M)
elif (x+1)*(x+1) <= N:
print((x+1)*(x+1))
else:
print("No perfect Square")
Comments
Leave a comment