  In this paper, we study the prescribed $Q$-curvature problem on closed
four-dimensional Riemannian manifolds when the total integral of the
$Q$-curvature is a positive integer multiple of the one of the four-dimensional
round sphere. This problem has a variational structure with a lack of
compactness. Using some topological tools of the theory of "critical points at
infinity" combined with a refined blow-up analysis and some dynamical
arguments, we identify the accumulations points of all noncompact flow lines of
a pseudogradient flow, the so called critical points at infinity of the
associated variational problem, and associate to them a natural Morse index. We
then prove strong Morse type inequalities, extending the full Morse theory to
this noncompact variational problem. Finally, we derive from our results
Poincar\'e-Hopf index type criteria for existence, extending known results in
the literature and deriving new ones.
