Counting primitive bit strings
johndcook.com