Friday, July 12, 2019

Squaring Numbers in Your Head

I mentioned that binomial expansion of (n+1)2 gives n2 +2n + 1, which makes this far easier to do in your head than multiplying and adding columns. Bu there is a more general solution. (n+i)2 gives n2 +2i + i2.  Now any power of 10 is easy to figure by factoring: 40 = 4 x 10 x 4 x 10 = 16 x 100. And therefore 452 is 402 + 2x5x40 + 52 = 1600 + 400 + 25 = 2000+25 = 2025.  This is really fast.

And even as the digit count grows:  2022 = 2002 + 4 x 200 + 22 = 40,000 + 800 + 4=n 40,804.  If you can factor by 2, awesome, but if you are within ten of a power of ten, this is easier.  I love figuring out techniques, which is why as a software engineer I always looked for ways to solve a requirement by building a tool which had an application to solve the problem.

1 comment:

Unknown said...

You have a very confusing typo, unfortunately, in this post. You say that "(n+i)^2 gives n2 +2i + i2". It should be "(n+i)^2 gives n2 +2ni + i2". You have it right in the example using 40 and 5.