What would be the time complexity of this function
bool prime(int n) {
if(n <= 1) {
return false;
} else if(n <= 3) {
return true;
} else if(n % 2 == 0 || n % 3 == 0) {
return false;
} else {
for(int i = 5; i * i <= n; i += 6) {
if(n % i == 0 || n % (i + 2) == 0) {
return false;
}
}
}
return true;
}
If I had to guess, it would be
O(sqrt(log(n)))
(i + 4)
as well? – Maze(i + 4)
– Rost