Find all positive integer $n$ and nonnegative integer $a_1,a_2,\dots,a_n$ satisfying:

$i$ divides exactly $a_i$ numbers among $a_1,a_2,\dots,a_n$, for each $i=1,2,\dots,n$.
($0$ is divisible by all integers.)

1. **Understanding the Problem:**
   We need to find all positive integers \( n \) and nonnegative integers \( a_1, a_2, \ldots, a_n \) such that for each \( i \) (where \( i = 1, 2, \ldots, n \)), \( i \) divides exactly \( a_i \) numbers among \( a_1, a_2, \ldots, a_n \).

2. **Initial Observations:**
   - If \( a_i = 0 \), then \( i \) divides 0, which is true for all \( i \). However, this would mean \( i \) divides all \( n \) numbers, contradicting the condition that \( i \) divides exactly \( a_i \) numbers.
   - Therefore, each \( a_i \) must be positive.

3. **Range of \( a_i \):**
   - Since \( a_i \) must be a nonnegative integer and \( i \) divides exactly \( a_i \) numbers, \( a_i \) must be at most \( n \). Hence, \( 1 \leq a_i \leq n \).

4. **Sequence Analysis:**
   - Consider the sequence \( a_1, a_2, \ldots, a_n \). For each \( i \), \( i \) must divide exactly \( a_i \) numbers in the sequence.
   - This implies that for each \( i \), there must be exactly \( a_i \) multiples of \( i \) in the sequence.

5. **Special Cases:**
   - For \( n = 1 \):
     - \( a_1 \) must be 1 because 1 divides exactly 1 number (itself). Thus, \( a_1 = 1 \).
   - For \( n = 2 \):
     - \( a_1 \) must be 2 because 1 divides both numbers in the sequence.
     - \( a_2 \) must be 1 because 2 divides exactly one number in the sequence.
     - Thus, \( a_1 = 2 \) and \( a_2 = 1 \).

6. **General Case:**
   - For \( n \geq 3 \):
     - Consider the sequence \( a_1, a_2, \ldots, a_n \). If \( n \geq 7 \), the sequence must include \( n, n-1, n-2, \ldots, \left\lfloor \frac{n}{2} \right\rfloor + 1 \) because each integer in this range only divides itself in the range \([1, n]\).
     - This leads to a contradiction because consecutive integers are relatively prime, and at least two of them will not be divisible by \( k \) for some \( k \).

7. **Verification for Small \( n \):**
   - For \( n = 3 \):
     - \( a_1 = 3 \) (1 divides all three numbers).
     - \( a_2 = 1 \) (2 divides exactly one number).
     - \( a_3 = 1 \) (3 divides exactly one number).
     - This does not satisfy the conditions because 2 and 3 do not divide exactly one number each.
   - For \( n = 4 \):
     - Similar contradictions arise.

8. **Conclusion:**
   - The only valid solutions are for \( n = 1 \) and \( n = 2 \).

The final answer is \( \boxed{ n = 1 } \) with \( a_1 = 1 \) and \( n = 2 \) with \( a_1 = 2, a_2 = 1 \).