Here's the algorithm we wrote for calculating integer powers: