# Solution to Diophantine equations

I am trying to solve a problem that boils down to finding the number of solutions of a linear Diophantine equation with restrictions. To be precise for equations :

$$ax + by + cz = k$$ and $$x + y + z = n$$

Refer the solution under "Diophantine Systems with Restrictions" on this page. How do I code this mathematical solution? My constraints include $$k$$ ranging from $$-10^{9}$$ to $$10^9$$ and $$n$$ from $$1$$ to $$10^5$$. Also, what would be the run time. I can code this but in a very haphazard and inefficient manner. Is there a neat or maybe a standard solution to this?