Use unsigned type for iteration to avoid int overflow.