Assume N is a power of 2: N = 2k.
int sum = 0; for(int n = N; n > 0; n /= 2) { for(int i = 0; i < n; i++) { sum++; } }