kids encyclopedia robot

Exponentiation by squaring facts for kids

Kids Encyclopedia Facts

Exponentiating by squaring is a clever algorithm (a set of steps) that helps you quickly figure out really big powers of a number. Imagine you need to calculate 2 multiplied by itself 100 times! This method makes it much faster than doing it the usual way. It's also known as the square-and-multiply algorithm or binary exponentiation. It uses the binary (base-2) way of writing the exponent (the small number that tells you how many times to multiply). This technique is super useful in many areas, like in modular arithmetic, which is a type of math used in computer science and cryptography.

People believe this algorithm was first written down in an ancient Sanskrit book called Chandah-sûtra, around 200 BC.

How the Squaring Algorithm Works

Calculating a number raised to a power, like xn (which means x multiplied by itself n times), can take a long time if n is a very large number. For example, to find 210, you could do 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2. That's 9 multiplications.

The squaring algorithm is much quicker! Instead of multiplying x by itself n times, it uses a trick. It works by repeatedly squaring the number and then multiplying only when needed.

Here's the basic idea:

  • If you want to find xn, and n is an even number, you can think of it as (x2)n/2. For example, 210 is the same as (22)5, which is 45. This reduces the problem.
  • If n is an odd number, you can write it as x × xn-1. Since n-1 is now an even number, you can use the trick from above. For example, 25 is 2 × 24. Then you can calculate 24 as (22)2, which is 42.

This method drastically cuts down the number of multiplications you need to do. Instead of n multiplications, you only need about log2(n) multiplications. This means for a huge power like 2100, you'd only need around 7 multiplications instead of 99! This makes calculations much faster for computers.

See also

kids search engine
Exponentiation by squaring Facts for Kids. Kiddle Encyclopedia.