Solving a linear Diophantine equation where c is a multiple of $7$ (or any other prime)

If $p$ is a prime, and given $a,b$ with $a$ is not divisible by $p,$ then there is some $a’$ such that $aa’-1=pm.$ Then your equation is equivalent $aa’x+ba’y=pka’$ or $x+ba’y=p(k-mx )$ so you get a parameterization: $$x=pk-(ba’)y$$

Note $a’$ and $m$ are determined by $a,$ so these answers are parameterized by $y.$


So for $(a,b,p)=(5,8,13),$ $a’=8,m=3.$ Then you get:

$$x=13k-64y$$

You can reduce $ba’$ modulo $p,$ which in this case reduces:

$$x=13k+y$$


If $a$ is divisible by $p$ and $b$ is not, $(x,y)$ is parameterized by $(n,pm).$ $y$ cannot take just any value in this case.

If $a,b$ are both divisible by $p,$ then the solutions are parameterized by $x=n-y.$


This is all best expressed modulo $p:$

$$ax\equiv (-b)y\pmod p$$ If $a$ is not divisible by $p,$ $a$ has a multiplicative inverse, modulo $p,$ and this came be expressed:

$$x\equiv (-a’b)y\pmod p$$ or $x=pn-a’by$ for some $n.$