Pozzo:一款快速幸运数字检查器
Pozzo: A Fast Lucky Number Checker

原始链接: https://github.com/Robert-Cunningham/pozzo

Pozzo 是一款高性能工具,专为测试大整数的“幸运性”(luckiness)而设计,该属性由类似于素数分布的筛法决定。通过在节省内存的位图上利用树状数组(Fenwick tree),Pozzo 的运行速度显著快于以往的方法,将各类 OEIS 数列的搜索空间扩大了 1,000 到 1 亿倍。 该算法使用筛法处理初始的幸运性检查,而基于排名的归约技术使程序能够验证远超筛法物理内存限制的单个候选数。在最近一次于 128GB 内存系统上进行的 12 小时测试中,该工具成功扩展了多个数列,包括幸运梅森数和幸运斐波那契数。值得注意的是,Pozzo 发现了显著更大的数值,例如第 18 个幸运十进制重复数字(一个 14 位数)和第 9 个幸运斐波那契数(约 72.7 万亿),有效地推动了这些整数数列的计算边界。

抱歉。
相关文章

原文

Pozzo tests large integers for luckiness. It is dramatically more efficient than its predecessors, increasing the number of values searched for several OEIS sequences by a factor of between 1,000 and 100,000,000.

Lucky numbers are produced by a sieve. From the OEIS Wiki:

Start with a sequence of positive odd numbers:

1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, ...

The first nonunit survivor is 3, so strike every third value in this list:

1, 3, [5], 7, 9, [11], 13, 15, [17], 19, 21, [23], 25, 27, [29], 31, ...

The next unused survivor is 7, so strike every seventh value of the new list.

1, 3, 7, 9, 13, 15, [19], 21, 25, 27, 31, 33, 37, [39], 43, ...

The values that are never struck out are the lucky numbers:

1, 3, 7, 9, 13, 15, 21, 25, 31, ...

Lucky numbers are of some interest because they share several statistical properties with primes.

To check k numbers for luckiness, we maintain a Fenwick tree over k bits, where each node counts the number of set bits in its range. By traversing this tree, we can very quickly look up and unset the ith set bit.

Memory constrains the size of the sieve. The sieve requires two bits per odd integer (one bit for the bitset, and one amortized bit for the Fenwick tree). This averages out to one integer per bit of RAM.

Note that this does not bound the maximum size of the numbers we can prove lucky; we can prove luckiness of candidates much higher than the sieve limit, with the following algorithm:

  1. Start each candidate at rank = (n + 1) / 2, the rank among odd numbers after deleting evens.
  2. For each lucky deletion factor l, reject when rank % l == 0.
  3. Otherwise update rank -= rank / l.
  4. Once rank < l, the candidate has survived all future deletions and is lucky.

And what hackathon project are you presenting today?

The integer 4,398,046,511,103.

After spending several hackathons making things like "Uber for dogs with hearing loss", I decided that my next project would be an off-the-shelf integer. It was a very Duchamp era of my life.

I wanted to extend an OEIS sequence, but which one? Ideally one where the values are rare enough to be exciting, but not so rare that we can't find a new one. Lucky numbers are distributed like $\log^{-1}(p)$, so sequences involving intersections with lucky numbers make reasonable targets. For example, A057613 (lucky numbers of the form 2^k - 1) is very promising.

Bold values are newly discovered.

1, 3, 7, 9, 33, 99, 111, 777, 9999, 33333, 55555, 111111, 777777, 7777777, 55555555, 777777777777, 9999999999999.

A031882: Lucky decimal repdigits.

Old bound: a(16) > 10^9

New bound: a(18) >= 777777777777777

Search space expanded by a factor of $8 * 10^5$.

1, 3, 7, 15, 31, 63, 127, 511, 1023, 4095, 8191, 131071, 524287, 2097151, 4194303, 8388607, 33554431, 67108863, 8589934591, 68719476735, 1099511627775, 4398046511103.

A057613: Lucky numbers of the form 2^k - 1.

Old bound: a(20) >= 2^34 - 1

New bound: a(23) >= 2^49 - 1

Search space expanded by a factor of $3 * 10^4$.

Lucky Mersennes With Prime Exponent

3, 7, 31, 127, 8191, 131071, 524287, 8388607.

A057612: Lucky numbers of the form 2^p - 1 for prime p.

Old bound: a(9) > 2^31 - 1

New bound: a(9) >= 2^59 - 1

Search space expanded by a factor of $3 * 10^8$.

1, 3, 13, 21, 1597, 6765, 75025, 32951280099.

A057589: Lucky Fibonacci numbers.

Old bound: a(8) >= 12586269025

New bound: a(9) >= 72723460248141

Search space expanded by a factor of $6 * 10^3$.

1, 3, 7, 3571, 9349, 710647, 12752043.

A306632: Lucky Lucas numbers.

Old bound: a(8) >= 10^9

New bound: a(8) >= 100501350283429

Search space expanded by a factor of $1 * 10^5$.

1, 15, 10671, 274423830033.

A140285: Lucky tetranacci numbers.

Old bound: a(4) >= 10312882481

New bound: a(5) >= 194314552299285

Search space expanded by a factor of $2 * 10^4$.

Lucky Consecutive-Digit Numbers

21, 43, 67, 87, 321, 4321, 4567, 6789, 78901, 432109, 9012345, 67890123, 109876543, 123456789, 6543210987, 8901234567, 9876543210987.

A118569: Lucky numbers with ascending or descending cyclic consecutive decimal digits.

Old bound: a(17) >= 10^10

New bound: a(18) >= 123456789012345

Search space expanded by a factor of $1 * 10^4$.

The reported run took about 12 hours on a machine with 128GB of RAM. The sieve covers approximately $2^{40}$ integers. The log can be found in pozzo.log.

cargo test
cargo run --release -- --memory-mib 114688

From Waiting for Godot.

I started this in 2019 and would certainly not have finished it without 2026-era coding agents, to whom most credit is due.

联系我们 contact @ memedata.com