What Does This Thing Do?

Determine what the following algorithm does, and then prove that it does what you think it does.

{Input: a real number a and a positive integer n.}
begin
p := 1
q := a
i := n
while i > 0 do
if i is odd then p := p*q
{Do the next two steps whether or not i is odd.}
q := q*q
i := i DIV 2 = floor(i/2)
return p
end

Please submit all answers to mathpotw@acu.edu, by 5:00 PM on Thursday, November 7.