a) Find all positive integers $g$ with the following property: for each odd prime number $p$ there exists a positive integer $n$ such that $p$ divides the two integers
\[g^n - n\quad\text{ and }\quad g^{n+1} - (n + 1).\]
b) Find all positive integers $g$ with the following property: for each odd prime number $p$ there exists a positive integer $n$ such that $p$ divides the two integers
\[g^n - n^2\quad\text{ and }g^{n+1} - (n + 1)^2.\]
### Part (a)

1. **Given Condition:**
   For each odd prime number \( p \), there exists a positive integer \( n \) such that:
   \[
   p \mid g^n - n \quad \text{and} \quad p \mid g^{n+1} - (n + 1)
   \]

2. **First Equation Analysis:**
   From \( p \mid g^n - n \), we have:
   \[
   g^n \equiv n \pmod{p}
   \]

3. **Second Equation Analysis:**
   From \( p \mid g^{n+1} - (n + 1) \), we have:
   \[
   g^{n+1} \equiv n + 1 \pmod{p}
   \]

4. **Relating the Two Equations:**
   Using \( g^{n+1} = g \cdot g^n \), we substitute \( g^n \equiv n \pmod{p} \):
   \[
   g \cdot n \equiv n + 1 \pmod{p}
   \]

5. **Simplifying the Congruence:**
   \[
   gn \equiv n + 1 \pmod{p} \implies n(g - 1) \equiv 1 \pmod{p}
   \]

6. **Implication for \( g - 1 \):**
   Since \( n \) and \( p \) are coprime, \( g - 1 \) must have a multiplicative inverse modulo \( p \). This implies \( g - 1 \) must be coprime to \( p \). Therefore, \( g - 1 \) must be a power of 2:
   \[
   g - 1 = 2^m \quad \text{for some} \quad m \in \mathbb{N}_0
   \]

7. **Checking for Contradictions:**
   If \( g \neq 2 \), then \( g \) must be even, and there exists an odd prime \( p \) such that \( p \mid g \). This leads to a contradiction because:
   \[
   g^n \equiv n \equiv 0 \pmod{p} \quad \text{and} \quad g^{n+1} \equiv n + 1 \equiv 0 \pmod{p} \implies n \equiv n + 1 \pmod{p}
   \]
   This is a contradiction, so \( g \) must be 2.

8. **Verification:**
   For \( g = 2 \):
   \[
   2^n \equiv n \pmod{p} \quad \text{and} \quad 2^{n+1} \equiv n + 1 \pmod{p}
   \]
   This implies:
   \[
   2n \equiv n + 1 \pmod{p} \implies n \equiv 1 \pmod{p}
   \]
   Using the Chinese Remainder Theorem, we can find \( n \) such that \( n \equiv 0 \pmod{p-1} \) and \( n \equiv 1 \pmod{p} \).

### Part (b)

1. **Given Condition:**
   For each odd prime number \( p \), there exists a positive integer \( n \) such that:
   \[
   p \mid g^n - n^2 \quad \text{and} \quad p \mid g^{n+1} - (n + 1)^2
   \]

2. **First Equation Analysis:**
   From \( p \mid g^n - n^2 \), we have:
   \[
   g^n \equiv n^2 \pmod{p}
   \]

3. **Second Equation Analysis:**
   From \( p \mid g^{n+1} - (n + 1)^2 \), we have:
   \[
   g^{n+1} \equiv (n + 1)^2 \pmod{p}
   \]

4. **Relating the Two Equations:**
   Using \( g^{n+1} = g \cdot g^n \), we substitute \( g^n \equiv n^2 \pmod{p} \):
   \[
   g \cdot n^2 \equiv (n + 1)^2 \pmod{p}
   \]

5. **Simplifying the Congruence:**
   \[
   gn^2 \equiv n^2 + 2n + 1 \pmod{p} \implies n^2(g - 1) \equiv 2n + 1 \pmod{p}
   \]

6. **Implication for \( g \):**
   Since \( n \) and \( p \) are coprime, \( g - 1 \) must be a power of 2:
   \[
   g - 1 = 2^m \quad \text{for some} \quad m \in \mathbb{N}_0
   \]

7. **Checking for Contradictions:**
   If \( g \neq 2 \), then \( g \) must be even, and there exists an odd prime \( p \) such that \( p \mid g \). This leads to a contradiction because:
   \[
   g^n \equiv n^2 \equiv 0 \pmod{p} \quad \text{and} \quad g^{n+1} \equiv (n + 1)^2 \equiv 0 \pmod{p} \implies n^2 \equiv (n + 1)^2 \pmod{p}
   \]
   This is a contradiction, so \( g \) must be a power of 2.

8. **Verification:**
   For \( g = 4 \):
   \[
   4^n \equiv n^2 \pmod{p} \quad \text{and} \quad 4^{n+1} \equiv (n + 1)^2 \pmod{p}
   \]
   This implies:
   \[
   4n^2 \equiv (n + 1)^2 \pmod{p} \implies n^2(4 - 1) \equiv 2n + 1 \pmod{p} \implies 3n^2 \equiv 2n + 1 \pmod{p}
   \]
   Solving this congruence, we find that \( g = 4 \) satisfies the condition.

The final answer is \( \boxed{ g = 2 } \) for part (a) and \( g = 4 \) for part (b).