Compute 'permutation' like problem with modulo
The idea is that $(a + b) \pmod{p} = ((a \pmod{p}) + (b \pmod{p})) \pmod{p}$ and $(ab) \pmod{p} = ((a\pmod{p})(b\pmod{p})\pmod{p}$. In C code, computing $a + bc \pmod{p}$ is accomplished by


  t = (b*c) % p;
  return (a + t) % p;


Regarding inverses, when $p$ is prime and $1 \leq a \leq p-1$ there is an element $1 \leq b \leq p-1$ satisfying $ab = 1 \pmod{p}$, and so $(x/a) \pmod{p} = (xb) \pmod{p}$. To find $b$ use the extended GCD algorithm to find $b,c$ such that $ab + cp = 1$.