Geometric genus of a surface, Exercise 21.5 D in Ravi Vakil's book I get stuck in Exercise 21.5 D in Ravi Vakil's book,
Suppose $Z$ is a regular degree $d$ surface in $\mathbb{P}^3_{\bar{k}}$, compute the geometric genus of $Z$.
The geometric genus is defined to be $p_g(Z)=h^0(Z,\mathcal{K}_Z)$ where $\mathcal{K}_Z$ is the canonical bundle. In this case from the adjunction formula
\begin{equation}
\mathcal{K}_Z=(\mathcal{K}_{\mathbb{P}^3_{\bar{k}}} ~\otimes \mathcal{O}_{\mathbb{P}^3_{\bar{k}}}(Z))|_Z=\mathcal{O}_{\mathbb{P}^3_{\bar{k}}}(-4+d)|_Z
\end{equation}
So how could we compute $h^0(Z,\mathcal{O}_{\mathbb{P}^3_{\bar{k}}}(-4+d)|_Z)$ ? It is trivial that when $d=4$, then it is just $h^0(Z,\mathcal{O}_Z)=1$, what about other cases? They seem to be 0, at least when d is smaller than 4. 
 A: Consider the short exact sequence
$$0 \longrightarrow \mathcal{O}_{\mathbf{P}^3}(-d) \longrightarrow \mathcal{O}_{\mathbf{P}^3} \longrightarrow \mathcal{O}_Z \longrightarrow 0$$
induced by multiplication by the defining equation. Tensoring by $\omega_{\mathbf{P}^3}(d) \cong \mathcal{O}_{\mathbf{P}^3}(d-4)$, we obtain
$$0 \longrightarrow \mathcal{O}_{\mathbf{P}^3}(-4) \longrightarrow \mathcal{O}_{\mathbf{P}^3}(d-4) \longrightarrow \mathcal{O}_{\mathbf{P}^3}(d-4)\rvert_Z \longrightarrow 0$$
Now take the long exact sequence on cohomology to get
$$\require{AMScd}\begin{CD}
  0 @>>> H^0(\mathcal{O}_{\mathbf{P}^3}(-4)) @>>> H^0(\mathcal{O}_{\mathbf{P}^3}(d-4)) @>>> H^0(\mathcal{O}_{\mathbf{P}^3}(d-4)\rvert_Z) @>>> H^1(\mathcal{O}_{\mathbf{P}^3}(-4))\\
  @. @| @| @| @|\\
  0 @>>> 0 @>>> k^{\binom{d-1}{3}} @>>> H^0(\mathcal{O}_{\mathbf{P}^3}(d-4)\rvert_Z) @>>> 0
\end{CD}
$$
where we understand $\binom{d-1}{3} = 0$ for $d-1 < 0$, by using Vakil's Theorem 18.1.3. This gives the formula
$$p_g = \frac{1}{3!} (d-1)(d-2)(d-3)$$
