  Let $R$ be a Cohen-Macaulay local ring of dimension $d$ with infinite residue
field. Let $I$ be an $R$-ideal that has analytic spread $\ell(I)=d$, $G_d$
condition and the Artin-Nagata property $AN^-_{d-2}$. We provide a formula
relating the length $\lambda(I^{n+1}/JI^{n})$ to the difference
$P_I(n)-H_I(n)$, where $J$ is a general minimal reduction of $I$, $P_I(n)$ and
$H_I(n)$ are the generalized Hilbert-Samuel polynomial and the generalized
Hilbert-Samuel function in the sense of C. Polini and Y. Xie. We then use it to
establish formulas to compute the higher generalized Hilbert coefficients of
$I$. As an application, we extend Northcott's inequality to non
$\mathfrak{m}$-primary ideals. When equality holds in the generalized
Northcott's inequality, the ideal $I$ enjoys nice properties. Indeed, in this
case, we prove that the reduction number of $I$ is at most one and the
associated graded ring of $I$ is Cohen-Macaulay. We also recover results of G.
Colom$\acute{{\rm e}}$-Nin, C. Polini, B. Ulrich and Y. Xie on the positivity
of the generalized first Hilbert coefficient $j_1(I)$. Our work extends that of
S. Huckaba, C. Huneke and A. Ooishi to ideals that are not necessarily
$\mathfrak{m}$-primary.
