Exact computation of the n-loop invariants