Division free counting algorithm