```python
import math

def get_Min_Squares(n):
    """
    Finds the minimum number of squares whose sum is equal to a given number n.
    This solution is based on Lagrange's four-square theorem and Legendre's
    three-square theorem.
    """
    if n <= 0:
        return 0

    # Case 1: n is a perfect square (sum of 1 square).
    # Example: 9 = 3^2
    sqrt_n = int(math.sqrt(n))
    if sqrt_n * sqrt_n == n:
        return 1

    # Case 4: n is of the form 4^k * (8m + 7) (sum of 4 squares).
    # By Legendre's three-square theorem, such numbers cannot be a sum of
    # one, two, or three squares.
    # Example: 7, 15, 23
    temp_n = n
    while temp_n % 4 == 0:
        temp_n //= 4
    if temp_n % 8 == 7:
        return 4

    # Case 2: n is a sum of two squares.
    # We check if n can be expressed as a^2 + b^2.
    # This is equivalent to checking if n - i^2 is a perfect square.
    # Example: 13 = 3^2 + 2^2
    limit = int(math.sqrt(n))
    for i in range(1, limit + 1):
        remainder = n - i * i
        sqrt_remainder = int(math.sqrt(remainder))
        if sqrt_remainder * sqrt_remainder == remainder:
            return 2

    # Case 3: n is a sum of three squares.
    # If none of the above conditions are met, the number must be a sum of three squares.
    # Example: 12 = 2^2 + 2^2 + 2^2
    return 3
```