solution with Gauss by mod