Replaced pow() with plain integer operations