Notice this: . If you compute once, you can square it to get . That's 1 multiplication instead of 5.
This is exponentiation by squaring. When is even, compute and square it. When is odd, compute , square it, and multiply by once more.
Each step cuts roughly in half. Instead of steps, you do steps. For , that's about 30 multiplications instead of a billion.