------
## 最终结论
```python
def numSquares(n):
    # Create a list to store the minimum number of perfect squares for each number up to n
    dp = [float('inf')] * (n + 1)
    dp[0] = 0  # Base case: 0 can be represented by 0 perfect squares

    # Iterate through all numbers from 1 to n
    for i in range(1, n + 1):
        # Check all perfect squares less than or equal to i
        j = 1
        while j * j <= i:
            dp[i] = min(dp[i], dp[i - j * j] + 1)
            j += 1

    return dp[n]

# Example usage:
print(numSquares(12))  # Output: 3
print(numSquares(13))  # Output: 2
```