Congruences- find the number of solutions 
*

*Find the number of solutions of $ a_1x_1+ ... +a_nx_n =$ b (mod m).


I was thinking of denoting $ d = (a_1,a_2,...,a_n,m)$.
Then the congruence has no solutions if $d$ doesn't divide $b$. And it has solutions when $d$ divides $b$.
I was thinking of using induction, but I didn't have a clear idea.(I think it may have $dm^{n-1}$ solutions ??)
Could someone please help me show the solutions of these questions more concretely?
1. Find the number of solutions to the congruence $ x^3-2x^2-x+2 = 0$ (mod 143) without finding the actual solutions.
 A: First Question:

Theorem :
  The congruence $a_1x_1+\cdots+a_nx_n\equiv b\mod m$ has exactly $gcd(a_1,\cdots,a_n,m)m^{n-1}$ when $gcd(a_1,\cdots,a_n,m)$ divides $b$, and no solution otherwise.

Proof: by induction:


*

*For $n=1$ let $d=gcd(a_1,m)$, $a=\frac{a_1}{d}$, $b'=\frac{b}{d}$ and $m'=\frac{m}{d}$ so the equation $ax \equiv b' \mod m'$ has exactly on solution $x_0$ in $\mathbb{Z_{m'}}$. which gives us $gcd(a,m)$ in $\mathbb{Z_{m}}$ ( the solutions are $x_0,x_0+m',\cdots,x_0+m'(d-1)$)

*Assume that the congruence $a_1x_1+\cdots+a_nx_n\equiv b\mod m$ has exactly $gcd(a_1,\cdots,a_n,m)m^{n-1}$ when $gcd(a_1,\cdots,a_n,m)$ divides $b$ for every  integers $a_1,\cdots,a_n,m,b$. let's consider a congruence with $n+1$ variables:
$$a_1x_1+\cdots+a_nx_n+a_{n+1}x_{n+1}\equiv b\mod m \ \ \ \ (*)$$
with surely the constraint $gcd(a_1,\cdots,a_n,a_{n+1},m)$ divides $b$, let $d=gcd(a_1,\cdots,a_n,m)$ and consider that $x_{n+1}$ is fixed,the equation $$a_1x_1+\cdots+a_nx_n\equiv b-a_{n+1}x_{n+1}\mod m \ \ \ (**)$$ has exactly $dm^{n-1}$ solution for every fixed $x_{n+1}$ such that $d|b-a_{n+1}x_{n+1}$ or $a_{n+1}x_{n+1}=b \mod d$ and ther is no solution otherwise. Now let's count the number of possible values of $x_{n+1} \mod m$, every possible value of $x_{n+1}$ it's a solution of :
$$ \left(\frac{ma_{n+1}}{d} \right)x_{n+1}\equiv \frac{bm}{d} \mod m $$
and because as hypothesis, $gcd(a_{n+1},d)=gcd(a_1,\cdots,a_{n+1},m)$ divides $b$ so $k=gcd\left(\frac{ma_{n+1}}{d},m\right)=m\frac{gcd(d,a_{n+1})}{d}$ divides $\frac{bm}{d}$ hence this equation has exactly $k$ solutions, so there is exactly $k$ values possible of $x_{n+1}$ for which the equation $(**)$ has solutions and has for each value of $k$ $dm^{d-1}$ solutions . So the total number of solutions of $(*)$ is exactly:
$$kdm^{n-1}=gcd(a_1,\cdots,a_{n+1},m)m^{n} $$
which terminates the proof.


Second Question: 
As pointed by @marty cohen, we have :
$$x^3-2x^2-x+2=(x-2)(x-1)(x+1) $$
this signifies that $x^3-2x^2-x+2\equiv 0 \mod 143$ if and only if $143$ divides $(x-1)(x+1)(x-2)$ so this is equivalent to $13$ divides one factor among $x-1$,$x+1$ and $x-2$ and $11$ also divides one factor among this factors. but every time we choose two factors we will deal with an equation of the form :
$$ x\equiv a_1 \mod 13\\x\equiv a_2 \mod 11$$
and because $gcd(11,13)=1$, the Chinese remainder theorem gives us the existence of an unique solution $\mod 13*11$ so the number of solutions is the number of ways of choosing two factors among $3$ which is $3^2=9$.
Verification by walframalpha.

Generalization:Given $m$ primes $p_1\cdots p_m$ and $n$ different integers $a_1,\cdots,a_n\in \mathbb{Z_{p_1\cdots p_m}}$, the equation $(x-a_1)\cdots(x-a_n)\equiv 0 \mod p_1\cdots p_m$ has exactly $n^m$ solutions.

A: For 1
(I guess the first problem is 0),
$x^3-2x^2-x+2 
=(x-2)(x^2-1)
=(x-2)(x-1)(x+1)
$
and
143 = 11*13.
Consider the possible values of $x$
that make
one or two terms in the product
divisible by 11 and 13.
