Number of Squares Python

PROGRAM TO FIND NUMBER OF SQUARES IN A RECTANGLE



def countSquares(m, n): 
      
    # If n is smaller, swap m and n 
    if(n < m): 
        temp =
        m =
        n = temp 
          
    # Now n is greater dimension, 
    # apply formula 
    return n * (n + 1) * (3 * m - n + 1) // 6
  
# Driver Code 
if __name__=='__main__'
    m = 4
    n = 3
    print("Count of squares is", countSquares(m, n)) 


OUTPUT
Count of Squares is 20

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java