avoid expensive math operations (logn)