Let $p>2$ be a prime. How many residues $\pmod p$ are both squares and squares plus one?
1. **Legendre Symbol and Quadratic Residues**:
   Let \(\left(\frac{a}{p}\right)\) denote the Legendre symbol, which is \(1\) if \(a\) is a quadratic residue (QR) modulo \(p\) and \(-1\) if \(a\) is a non-quadratic residue (NQR) modulo \(p\). We are interested in counting the number of residues \(a \pmod{p}\) such that both \(a\) and \(a+1\) are QRs.

2. **Expression for Counting Pairs**:
   Consider the expression:
   \[
   \frac{1}{4}\left[\left(\frac{a}{p}\right) + 1\right]\left[\left(\frac{a+1}{p}\right) + 1\right]
   \]
   for \(a \in \{1, 2, \ldots, p-2\}\). This expression is \(1\) if both \(a\) and \(a+1\) are QRs and \(0\) otherwise.

3. **Summing Over All \(a\)**:
   We sum this expression over all \(a\) from \(1\) to \(p-2\):
   \[
   \sum_{a=1}^{p-2} \frac{1}{4}\left[\left(\frac{a}{p}\right) + 1\right]\left[\left(\frac{a+1}{p}\right) + 1\right]
   \]
   This sum counts the number of pairs \((a, a+1)\) such that both \(a\) and \(a+1\) are QRs.

4. **Special Cases**:
   - For \(a = 0\), the pair \((0, 1)\) is always a QR.
   - For \(a = -1\), the pair \((-1, 0)\) is valid if \(-1\) is a QR. We add \(\frac{1}{2}\left(\left(\frac{-1}{p}\right) + 1\right)\) to account for this.

5. **Combining the Counts**:
   Thus, the total count is:
   \[
   \frac{3}{2} + \frac{1}{2}\left(\frac{-1}{p}\right) + \sum_{a=1}^{p-2} \frac{1}{4}\left[\left(\frac{a}{p}\right) + 1\right]\left[\left(\frac{a+1}{p}\right) + 1\right]
   \]

6. **Simplifying the Sum**:
   We expand the sum:
   \[
   \frac{3}{2} + \frac{1}{2}\left(\frac{-1}{p}\right) + \frac{1}{4}\sum_{a=1}^{p-2} \left(\left(\frac{a}{p}\right)\left(\frac{a+1}{p}\right) + \left(\frac{a}{p}\right) + \left(\frac{a+1}{p}\right) + 1\right)
   \]

7. **Evaluating Each Term**:
   - \(\sum_{a=1}^{p-2} \left(\frac{a}{p}\right)\left(\frac{a+1}{p}\right) = \sum_{a=1}^{p-2} \left(\frac{a^2 + a}{p}\right)\)
   - \(\sum_{a=1}^{p-2} \left(\frac{a}{p}\right)\)
   - \(\sum_{a=1}^{p-2} \left(\frac{a+1}{p}\right)\)
   - \(\sum_{a=1}^{p-2} 1 = p-2\)

8. **Simplifying the First Sum**:
   Using properties of the Legendre symbol and the fact that \(\left\{1 + \frac{1}{1}, 1 + \frac{1}{2}, \ldots, 1 + \frac{1}{p-2}\right\} = \left\{2, 3, \ldots, p-1\right\} \pmod{p}\):
   \[
   \sum_{a=1}^{p-2} \left(\frac{a^2 + a}{p}\right) = \sum_{a=1}^{p-2} \left(\frac{1 + \frac{1}{a}}{p}\right) = -1
   \]

9. **Simplifying the Second and Third Sums**:
   Using the fact that there are as many QRs as NQRs:
   \[
   \sum_{a=1}^{p-2} \left(\frac{a}{p}\right) = -\left(\frac{-1}{p}\right) + \sum_{a=1}^{p-1} \left(\frac{a}{p}\right) = -(-1)^{\frac{p-1}{2}}
   \]

10. **Combining All Terms**:
    \[
    \frac{3}{2} + \frac{1}{2}\left(\frac{-1}{p}\right) - \frac{1}{4} - \frac{(-1)^{\frac{p-1}{2}}}{4} - \frac{1}{4} + \frac{p-2}{4}
    \]

11. **Final Simplification**:
    \[
    \frac{3}{2} + \frac{1}{2}\left(\frac{-1}{p}\right) - \frac{1}{4} - \frac{(-1)^{\frac{p-1}{2}}}{4} - \frac{1}{4} + \frac{p-2}{4} = \boxed{\frac{p + (-1)^{\frac{p-1}{2}} + 2}{4}}
    \]