I have this little exercise:
for ( i = 0; i < 2 * n; i += 2 )
for ( j = 1; j <= n; j <<= 1 )
if ( j & i )
foo ();
(j <<= 1 means j = (j << 1), where << is the bitwise left shift operator. & is the bitwise and operator.)
I am supposed to determine how many times will the foo function be called for some n. The result should be both an exact number (or the most accurate approximation possible) and asymptotic (like O(n)).