Perfect Squares in a Range
You are given two given numbers, A and B where 1 <= A <= B, Write a program to find the number of perfect squares in the range A to B (including A and B).
Input
The first line of input is an integer A. The second line of input is an integer B.
Explanation
In the given example,
A = 9 and B = 100. The perfect squares in the range A to B are
3 * 3 = 9
4 * 4 = 16
5 * 5 = 25
6 * 6 = 36
7 * 7 = 49
8 * 8 = 64
9 * 9 = 81
10 * 10 = 100
So, the output should be
8.
Sample Input 1
9
100
Sample Output 1
8
Sample Input 2
625
1444
Sample Output 2
14
A = int(input())
B = int(input())
count=0
for i in range(A, B + 1):
if i ** 0.5 == int(i ** 0.5):
count+=1
print(count)
Comments
Leave a comment