Doubt in code lines of miller function

if a[i] is greater than n-2 than here its given continue but actually a should be in range of 2 to n-2 .so if a becomes >(n-2) then beak condition should be applied?

and in other line
if(ad%n==1) then here why continue is given?
can’t we consider n as prime only if the above ccondition is satisfied

Why is it given if a[i] >n-2 ; continue is because , is because these number should be in the range of 2,n-2 so if it’s greater then n-2 , it means that we don’t need that number and we’ll continue because it should be in a given range.
Why we are doing ad%n ==1 is because if this holds true, n can be a prime number but might not be. So just to check we are running for loop. If you still have doubt in this refer this


It will clear all your doubt as it’s detailed descriptive.

Moreover you can also take reference from this https://youtu.be/RNxr7km8lHo

i have doubt in the said lines of this code and this code and geeks for geeks code is different .so please give explanation of the said 2 lines of this code

sorry first i had just got link of geeks for geeks now i got text of your explanation

2 conditions are given that (a^d)%n=1 and (a^(d2i))=n-1.so is it that that if any of these condition becomes true then n is prime or any 1 condition should be true?

Both the statements need to be true that’s why we are breaking problem into further part and running for loop for this condition.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.