Efficient solution of linear diophantine equations