The synthetic division table is:
$$ \begin{array}{c|rrrr}5&1&-3&-18&40\\& & 5& 10& \color{black}{-40} \\ \hline &\color{blue}{1}&\color{blue}{2}&\color{blue}{-8}&\color{orangered}{0} \end{array} $$The solution is:
$$ \frac{ x^{3}-3x^{2}-18x+40 }{ x-5 } = \color{blue}{x^{2}+2x-8} $$Step 1 : Write down the coefficients of the dividend into division table. Put the zero from $ x -5 = 0 $ ( $ x = \color{blue}{ 5 } $ ) at the left.
$$ \begin{array}{c|rrrr}\color{blue}{5}&1&-3&-18&40\\& & & & \\ \hline &&&& \end{array} $$Step 1 : Bring down the leading coefficient to the bottom row.
$$ \begin{array}{c|rrrr}5&\color{orangered}{ 1 }&-3&-18&40\\& & & & \\ \hline &\color{orangered}{1}&&& \end{array} $$Step 2 : Multiply by the number on the left, and carry the result into the next column: $ \color{blue}{ 5 } \cdot \color{blue}{ 1 } = \color{blue}{ 5 } $.
$$ \begin{array}{c|rrrr}\color{blue}{5}&1&-3&-18&40\\& & \color{blue}{5} & & \\ \hline &\color{blue}{1}&&& \end{array} $$Step 3 : Add down last column: $ \color{orangered}{ -3 } + \color{orangered}{ 5 } = \color{orangered}{ 2 } $
$$ \begin{array}{c|rrrr}5&1&\color{orangered}{ -3 }&-18&40\\& & \color{orangered}{5} & & \\ \hline &1&\color{orangered}{2}&& \end{array} $$Step 4 : Multiply by the number on the left, and carry the result into the next column: $ \color{blue}{ 5 } \cdot \color{blue}{ 2 } = \color{blue}{ 10 } $.
$$ \begin{array}{c|rrrr}\color{blue}{5}&1&-3&-18&40\\& & 5& \color{blue}{10} & \\ \hline &1&\color{blue}{2}&& \end{array} $$Step 5 : Add down last column: $ \color{orangered}{ -18 } + \color{orangered}{ 10 } = \color{orangered}{ -8 } $
$$ \begin{array}{c|rrrr}5&1&-3&\color{orangered}{ -18 }&40\\& & 5& \color{orangered}{10} & \\ \hline &1&2&\color{orangered}{-8}& \end{array} $$Step 6 : Multiply by the number on the left, and carry the result into the next column: $ \color{blue}{ 5 } \cdot \color{blue}{ \left( -8 \right) } = \color{blue}{ -40 } $.
$$ \begin{array}{c|rrrr}\color{blue}{5}&1&-3&-18&40\\& & 5& 10& \color{blue}{-40} \\ \hline &1&2&\color{blue}{-8}& \end{array} $$Step 7 : Add down last column: $ \color{orangered}{ 40 } + \color{orangered}{ \left( -40 \right) } = \color{orangered}{ 0 } $
$$ \begin{array}{c|rrrr}5&1&-3&-18&\color{orangered}{ 40 }\\& & 5& 10& \color{orangered}{-40} \\ \hline &\color{blue}{1}&\color{blue}{2}&\color{blue}{-8}&\color{orangered}{0} \end{array} $$Bottom line represents the quotient $ \color{blue}{ x^{2}+2x-8 } $ with a remainder of $ \color{red}{ 0 } $.