Time complexity of this primality testing algorithm?
问题 I have the following code which determines whether a number is prime: public static boolean isPrime(int n){ boolean answer = (n>1)? true: false; for(int i = 2; i*i <= n; ++i) { System.out.printf("%d\n", i); if(n%i == 0) { answer = false; break; } } return answer; } How can I determine the big-O time complexity of this function? What is the size of the input in this case? 回答1: Think about the worst-case runtime of this function, which happens if the number is indeed prime. In that case, the