How many times will the function be invoked?

advertisements

I have this cycle:

for(i = 0; i < n; i ++) {
    if(i % 5 == 1 && i % 3 == 1) {
        function();
    }
}

How can i count amount of calls of function() without running this code?


I take from the complexity-theory tag that you want some Theta expression. The if causes your function to be executed every fifteenth time, which is a constant factor, so the number of executions is still Theta(n).