Minimum squares to evenly cut a rectangle | Javascript program to find minimum number of squares to make a given rectangle . ; if we take gcd ( l , w ) , this will be largest possible side for square , hence minimum number of square . ; Number of squares . ; Driver code
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function countRectangles ( l , w ) { let squareSide = __gcd ( l , w ) ; return parseInt ( ( l * w ) / ( squareSide * squareSide ) ) ; } let l = 4 , w = 6 ; document . write ( countRectangles ( l , w ) ) ;