According to Theorem 5.1 of http://math.mit.edu/~rstan/pubs/pubfiles/35.pdf, the number is $$ \frac 1p\left[ 2^{p-1}+\frac{p-1}{2}(\epsilon^{4h} + \epsilon^{-4h})\right], $$ where $h$ is the class number of $\mathbb{Q}(\sqrt{p})$ and $\epsilon>1$ the fundamental unit of $\mathbb{Q}(\sqrt{p})$.