For each positive integer $n$ , define $a_n = 20 + n^2$ and $d_n = gcd(a_n, a_{n+1})$. Find the set of all values that are taken by $d_n$ and show by examples that each of these values is attained.
To find the set of all values taken by \( d_n = \gcd(a_n, a_{n+1}) \) where \( a_n = 20 + n^2 \), we start by expressing \( a_{n+1} \) in terms of \( a_n \):

\[ a_{n+1} = 20 + (n+1)^2 = 20 + n^2 + 2n + 1 = a_n + 2n + 1 \]

Thus, we need to find:

\[ d_n = \gcd(a_n, a_{n+1}) = \gcd(20 + n^2, 20 + n^2 + 2n + 1) \]

Using the property of the greatest common divisor, we have:

\[ \gcd(a, b) = \gcd(a, b - a) \]

So,

\[ d_n = \gcd(20 + n^2, (20 + n^2 + 2n + 1) - (20 + n^2)) = \gcd(20 + n^2, 2n + 1) \]

Now, we need to analyze the values of \( \gcd(20 + n^2, 2n + 1) \) for different values of \( n \). We will consider three cases based on the value of \( n \mod 3 \):

1. **Case 1: \( n \equiv 0 \pmod{3} \)**
   - Let \( n = 3k \)
   - Then, \( a_n = 20 + (3k)^2 = 20 + 9k^2 \)
   - \( a_{n+1} = 20 + (3k+1)^2 = 20 + 9k^2 + 6k + 1 \)
   - \( d_n = \gcd(20 + 9k^2, 20 + 9k^2 + 6k + 1) = \gcd(20 + 9k^2, 6k + 1) \)

2. **Case 2: \( n \equiv 1 \pmod{3} \)**
   - Let \( n = 3k + 1 \)
   - Then, \( a_n = 20 + (3k+1)^2 = 20 + 9k^2 + 6k + 1 \)
   - \( a_{n+1} = 20 + (3k+2)^2 = 20 + 9k^2 + 12k + 4 \)
   - \( d_n = \gcd(20 + 9k^2 + 6k + 1, 20 + 9k^2 + 12k + 4) = \gcd(20 + 9k^2 + 6k + 1, 6k + 3) \)

3. **Case 3: \( n \equiv 2 \pmod{3} \)**
   - Let \( n = 3k + 2 \)
   - Then, \( a_n = 20 + (3k+2)^2 = 20 + 9k^2 + 12k + 4 \)
   - \( a_{n+1} = 20 + (3k+3)^2 = 20 + 9k^2 + 18k + 9 \)
   - \( d_n = \gcd(20 + 9k^2 + 12k + 4, 20 + 9k^2 + 18k + 9) = \gcd(20 + 9k^2 + 12k + 4, 6k + 5) \)

We now simplify each case:

1. **Case 1:**
   \[ d_n = \gcd(20 + 9k^2, 6k + 1) \]
   Since \( 6k + 1 \) is relatively prime to 3, the gcd is 1.

2. **Case 2:**
   \[ d_n = \gcd(20 + 9k^2 + 6k + 1, 6k + 3) \]
   Simplifying, we get:
   \[ d_n = \gcd(20 + 9k^2 + 6k + 1, 3(2k + 1)) \]
   Since \( 2k + 1 \) is relatively prime to 3, the gcd is 3.

3. **Case 3:**
   \[ d_n = \gcd(20 + 9k^2 + 12k + 4, 6k + 5) \]
   Simplifying, we get:
   \[ d_n = \gcd(20 + 9k^2 + 12k + 4, 6k + 5) \]
   Since \( 6k + 5 \) is relatively prime to 3, the gcd is 1.

Thus, the possible values of \( d_n \) are 1 and 3. However, we need to check for higher powers of 3:

- For \( n = 3k + 1 \), we get:
  \[ d_n = 3 \cdot \gcd(3k^2 + 2k + 7, 2k + 1) \]
  This can yield higher powers of 3 depending on the value of \( k \).

By checking specific values, we find that the set of all values taken by \( d_n \) is:

\[ \{1, 3, 9, 27, 81\} \]

The final answer is \( \boxed{ \{1, 3, 9, 27, 81\} } \).