It's been a while, but I believe that you can solve integer programming problems of this type using Groebner bases. (Google for "integer programming with Groebner bases"). I have some Groebner basis code in Haskell at http://www.polyomino.f2s.com/david/haskell/commalg.html