algorithm - Hamming weight of an interval -


my task calculate number of 1-bits of interval [1,10^16]. loop unusable case, , i've heard there exists algorithm this. can help?

more generally, algorithm number of 1-bits in interval [1,n] nice.

if helps, figured number of 1-bits of interval [1,2^n-1], n positive integer, n*2^(n-1).

the number of 1-bits in interval [1,n] number of 1-bits in interval [1,2^m] plus number of 1-bits in interval [1,n-2^m] plus n - 2^m.

m ⌊log(n)/log2⌋.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -