```python
def count_Squares(m, n):
    """
    Calculates the total number of squares in an m x n rectangle.
    
    The number of squares of size i x i in an m x n rectangle is (m - i + 1) * (n - i + 1).
    The total number of squares is the sum over all possible square sizes i,
    from 1 up to min(m, n).
    
    Sum_{i=1 to min(m,n)} (m - i + 1) * (n - i + 1)
    
    This sum can be simplified to a closed-form O(1) formula.
    Let l = max(m, n) and s = min(m, n).
    The formula is: s * (s + 1) * (3 * l - s + 1) / 6
    """
    if m < n:
        m, n = n, m
    
    # n is now the smaller dimension
    return n * (n + 1) * (3 * m - n + 1) // 6
```