The numbers $ 0$, $ 1$, $ \dots$, $ n$ ($ n \ge 2$) are written on a blackboard. In each step we erase an integer which is the arithmetic mean of two different numbers which are still left on the blackboard. We make such steps until no further integer can be erased. Let $ g(n)$ be the smallest possible number of integers left on the blackboard at the end. Find $ g(n)$ for every $ n$.
1. **Case 1: \( n \) is a power of 2**

   Suppose \( n = 2^m \) for some integer \( m \). We can fix the numbers \( 0 \) and \( n \) on the blackboard. We will show that we can erase all other numbers.

   - Initially, we have the numbers \( 0, 1, 2, \ldots, n \) on the blackboard.
   - We can erase the numbers \( 1, 3, 5, \ldots, n-1 \) because each of these numbers is the arithmetic mean of two other numbers still on the blackboard. For example, \( 1 \) is the mean of \( 0 \) and \( 2 \), \( 3 \) is the mean of \( 2 \) and \( 4 \), and so on.
   - After erasing these numbers, we are left with \( 0, 2, 4, \ldots, n \).
   - We can then erase \( 2, 6, 10, \ldots, n-2 \) because each of these numbers is the arithmetic mean of two other numbers still on the blackboard. For example, \( 2 \) is the mean of \( 0 \) and \( 4 \), \( 6 \) is the mean of \( 4 \) and \( 8 \), and so on.
   - We continue this process, erasing numbers of the form \( 2^k \cdot (2i+1) \) for \( k = 0, 1, \ldots, m-1 \) and \( i \) such that \( 2^k \cdot (2i+1) < n \).

   By this method, we can erase all numbers except \( 0 \) and \( n \). Therefore, \( g(n) = 2 \) when \( n \) is a power of 2.

2. **Case 2: \( n \) is not a power of 2**

   Suppose \( n \) is not a power of 2. Let \( n = 2^m + a \) where \( 0 < a < 2^m \).

   - We will not erase \( 0 \), \( 2^m \), or \( n \).
   - We can erase \( n-1, n-2, \ldots, 2^m+1 \) because each of these numbers is the arithmetic mean of two other numbers still on the blackboard. For example, \( n-1 \) is the mean of \( n \) and \( n-2 \), \( n-2 \) is the mean of \( n-1 \) and \( n-3 \), and so on.
   - We can then erase \( 1, 2, \ldots, 2^m-1 \) in the same way as in the first case.

   By this method, we can leave \( 0 \), \( 2^m \), and \( n \) on the blackboard. Therefore, \( g(n) = 3 \) when \( n \) is not a power of 2.

3. **Proof that \( g(n) \) cannot be less than claimed**

   - Notice that \( 0 \) and \( n \) cannot be erased because they are the endpoints of the range.
   - If \( n \) is not a power of 2, there exists a prime \( p > 2 \) such that \( p \mid n \). Suppose, for the sake of contradiction, that \( g(n) = 2 \). Then the only numbers left are \( 0 \) and \( n \).
   - If there is a series of steps that can leave only \( 0 \) and \( n \), we can reverse these steps by writing the integer that is the arithmetic mean of two different numbers on the board (which, initially, are \( 0 \) and \( n \)).
   - By writing in this fashion, all new numbers must be divisible by \( p \). In particular, we cannot get \( 1 \), which leads to a contradiction.

Therefore, \( g(n) \) cannot be less than 2 when \( n \) is a power of 2, and it cannot be less than 3 when \( n \) is not a power of 2.

\(\blacksquare\)

The final answer is \( \boxed{ g(n) = 2 } \) when \( n \) is a power of 2, and \( g(n) = 3 \) when \( n \) is not a power of 2.