View Single Post
Old 2004-05-28, 16:58   #2
May 2004

24·5 Posts

The algorithm you've given is probably close to optimal for computing the square of all integers 1 <= x <= max.

However, if you only want the square of only one number then straightforward multiplication is much quicker. For the range 1 <= x <= 60000, there is no quicker way to square a number than just "y = x * x;"

For larger numbers whose squares don't fit in a word, there are more efficient algorithms. A description of many of them is given on Carey Bloodworth's page
dave_dm is offline   Reply With Quote