Hacker News new | ask | show | jobs
by qsort 359 days ago
It's easier to write code for efficiently computing the inverse in that form, roughly:

  int FastExp(int a, int e, int p)
  {
    if (e == 0) return 1;
    if (e == 1) return a;
    if (e % 2 == 0) return FastExp((a*a)%p, e/2, p);
    else return a * FastExp((a*a)%p, e/2, p);
  }
In math competitions where you only have pen and paper, you'd instead turn what you wrote into a Diophantine equation you can solve with the usual method.