Begin28. Given a number \(A\). Compute \(A^{15}\) using two auxiliary variables and five multiplication operations. For this, sequentially find \(A^2, A^3, A^5, A^{10}, A^{15}\). Output all found powers of \(A\).

Solution in Python 3:

import random

A = random.randrange(0, 10)
A = 2
print("A = ",A)
x = A*A
print("A^2 = ",x)
A = x*A
print("A^3 = ",A)
A = x*A
print("A^5 = ",A)
x = A*A
print("A^10 = ",x)
A = x*A
print("A^15 = ",A)