Skip to main content
1 of 4
Lereu
  • 111
  • 3

Time complexity of Jacobi symbol

I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject).

Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right after that come my thoughts about it:

enter image description here

The if-cases in the lines $1$ up to $20$ and $32$ up to $37$ are checked in $\mathcal{O}(1)$.

In lines $21$ and $22$, the symbol is reduced. My guess it that this can happen at most $n$ times, so this would be $\mathcal{O}(n)$.

The remaining if-case in line $24$ divided the number $a$ by $2$ as often as possible. This is done in $\mathcal{O}(\log_2(n))$ times.

I really struggle determining complexity, so I would appreciate any feedback!

Lereu
  • 111
  • 3