code: function inverseModInt(x, n) {
    var a=1, b=0, t;
    for (;;) {
      if (x==1) return a;
      if (x==0) return 0;
      b-=a*Math.floor(n/x);
      n%=x;
  
      if (n==1) return b; //to avoid negatives, change this b to n-b, and each -= to +=
      if (n==0) return 0;
      a-=b*Math.floor(x/n);
      x%=n;
    }
  }
docs: return x**(-1) mod n, for integers x and n.  Return 0 if there is no inverse