Sep 17, 2024
i is initialized to 2.i is less than or equal to sqrt(n).n mod i == 0 is true, it indicates n is not a prime number and returns 0, terminating the loop early.sqrt(n).sqrt(n) - 1 times.sqrt(n).sqrt(n) - 1, leading to Tn = theta(sqrt(n)).sqrt(n)) and Tn = Omega(sqrt(n)).n mod 2 == 0.sqrt(n) - 1 times.sqrt(n)).sqrt(n)) (worst case)sqrt(n)) and Tn is Omega(1).