Given a range A & B, print the count of number of perfect squares between A & B (both inclusive)
A Perfect square is an integer which is the square of any integer.
For example, 1, 4, 9, 16 are some of the square integers as they are squares of 1, 2, 3, 4 respectively.
Method 1:
Implementation:
Input
First line - T, the number of test cases.
T test cases follow, Two space separated integers denoting A and B.
Output
Print the required count of perfect squares between the given range.
Sample Input
2 3 9 17 24
Sample output
2 0
A Perfect square is an integer which is the square of any integer.
For example, 1, 4, 9, 16 are some of the square integers as they are squares of 1, 2, 3, 4 respectively.
Method 1:
Implementation:
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { unsigned long long int i,x; int T,count,A,B; scanf("%d",&T); while(T--) { scanf("%d %d",&A,&B); count=0; for(i=A;i<=B;i++) { x=sqrt(i); if(x*x==i) { count++; } } printf("%d\n",count); } return 0; }
Input
First line - T, the number of test cases.
T test cases follow, Two space separated integers denoting A and B.
Output
Print the required count of perfect squares between the given range.
Sample Input
2 3 9 17 24
Sample output
2 0