Article 476YK How fast can you multiply really big numbers?

How fast can you multiply really big numbers?

by
John
from John D. Cook on (#476YK)

How long does it take to multiply very large integers? Using the algorithm you learned in elementary school, it takes O(n^2) operations to multiply two n digit numbers. But for large enough numbers it pays to carry out multiplication very differently, using FFTs.

If you're multiplying integers with tens of thousands of decimal digits, the most efficient algorithm is the Schinhage-Strassen algorithm, which takes

O(n log n log log n)

operations. For smaller numbers, another algorithm, such as Karatsuba's algorithm, might be faster. And for impractically large numbers, Fi1/4rer's algorithm is faster.

What is impractically large? Let's say a number is impractically large if storing it requires more than a billion dollars worth of RAM. If I did my back-of-the-envelop math correctly, you can buy enough RAM to store about 257 bits for about a billion dollars. The Schinhage-Strassen algorithm is more efficient than Fi1/4rer's algorithm for numbers with less than 264 bits.

Related post: How fast can you multiply matrices?

vFsBevSUAJk
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments