------
## 最终结论
```python
def min_replacements(n):
    count = 0
    while n != 1:
        if n % 2 == 0:
            n //= 2
        else:
            if (n == 3) or ((n & 2) == 0):
                n -= 1
            else:
                n += 1
        count += 1
    return count

# Example usage:
print(min_replacements(8)) # Output: 3
print(min_replacements(7)) # Output: 4
```