Number of perfect squares between two given numbers | An Efficient Method to count squares between a and b ; An efficient solution to count square between a and b ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSquares ( int a , int b ) { return ( floor ( sqrt ( b ) ) - ceil ( sqrt ( a ) ) + 1 ) ; } int main ( ) { int a = 9 , b = 25 ; cout << " Count ▁ of ▁ squares ▁ is ▁ " << countSquares ( a , b ) ; return 0 ; }