且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

需要关于如何在 JavaScript 中分解非常大的数字的提示/建议

更新时间:2023-11-18 18:44:46

最多 12 位是 100,000,000,000.这是很多素数(~ N/log N = 3,948,131,653).

up to 12 digits is 100,000,000,000. That's a lot of primes (~ N/log N = 3,948,131,653).

所以,制作一个高达 10^6 的筛子,将其压缩成约 78,500 个核心素数的数组,并使用它们逐段筛选直至您的目标.使用最多为段当前上限的平方根的素数.通常选择段的大小以使其适合系统缓存.筛选每个片段后,收集其质数.

So, make a sieve up to 10^6, compress it into the array of ~78,500 core primes, and use them to sieve segment by segment all the way up to your target. Use primes up to the square root of the current upper limit of the segment. The size of the segment is usually chosen so that it fits into system cache. After sieving each segment, collect its primes.

这被称为埃拉托色尼的分段筛.

This is known as segmented sieve of Eratosthenes.