Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

An algorithm to find even sublime numbers

A perfect number is a positive integer whose sum of divisors (except itself) is equal to itself. E.g. 6 (1 + 2 + 3 = 6) and 28 (1 +たす 2 +たす 4 +たす 7 +たす 14 = 28) are perfect.

A sublime number (OEIS A081357) is a positive integer whose count and sum of divisors (including itself) are both perfect. E.g. 12 is a sublime number because:

  • the divisors of 12 are 1, 2, 3, 4, 6, 12
  • the count of divisors is 6 (perfect)
  • the sum of divisors is 28 (perfect)

The next smallest known sublime number is

6086555670238378989670371734243169622657830773351885970528324860512791691264

and these two numbers are the only known sublime numbers as of 2022. The necessary and sufficient conditions for even sublime numbers have been found in this paper (pdf), but it remains unknown whether odd sublime numbers exist.

The paper outlines the "algorithm" to find even sublime numbers:

Suppose \$p\$ is a prime with the following properties,

  • \$q = 2^p − 1\$ is a prime.
  • \2ドル^q − 1\$ is a prime.
  • \$q − 1\$ can be partitioned into distinct primes \$l_1, \cdots , l_{p−1}\$ such that \$m_i = 2^{l_i} − 1\$ are also prime for all \$i\$.

Then \$n = 2^{q−1} ( \prod{m_i} )\$ is a sublime number.

This heavily relies on Mersenne primes, which are primes in the form of \2ドル^n-1\$. Let's define Mersenne exponents be the values of \$n\$ such that \2ドル^n-1\$ is prime. The list of known Mersenne exponents can be found on this Wikipedia page; it starts with

2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, ...

and only around 50 such exponents are known.

We can rewrite the algorithm in terms of a known set \$L\$ of Mersenne exponents:

Loop over \$p \in L\$:

  • Check that \$q = 2^p - 1 \in L\$. If so,
  • For each subset \$\{ l_i \}\$ of \$L\$ of size \$p-1\$:
    • If it sums to \$q-1\$,
    • output \$n = 2^{q-1} ( \prod{(2^{l_i}-1)} )\$ as a sublime number found.

Since the list of actual Mersenne exponents is fairly limited, we wouldn't get any more sublime numbers by using this algorithm on it. So let's run it on an arbitrary set of positive integers instead.

Challenge

Given a set of positive integers \$L\$, evaluate all possible outputs (values of \$n\$) the algorithm above would give you. Since \$p=1\$ is kind of an edge case, you may assume that \$L\$ does not contain 1.

You may assume that \$L\$ is nonempty. If you take \$L\$ as a list (as opposed to an unordered set), you may assume that it is sorted. You may output the values of \$n\$ in any order, and may output the same value multiple times. If multiple subsets satisfy the condition for a single \$p\$, all possible resulting \$n\$s must be output.

Standard rules apply. The shortest code in bytes wins.

Examples

If \$L=\{2,3\}\$, \$p=2\$ satisfies the condition:

  • 2 is in \$L\$ and \2ドル^2-1 = 3\$ is also in \$L\$.
  • A subset of size \$p-1 = 1\$ with sum \$q-1 = 2\$ exists: \$\{2\}\$.
  • The output is \$n = 2^{3-1} (2^2-1) = 12\$.

For \$L = \{2, 3, 4, 7\}\$, \$p=3\$ also does:

  • 3 is in \$L\$ and \2ドル^3-1 = 7\$ is also in \$L\$.
  • A subset of size \$p-1 = 2\$ with sum \$q-1 = 6\$ exists: \$\{2,4\}\$. (\$\{3,3\}\$ does not work since it is just \$\{3\}\$.)
  • The output is \$n = 2^{7-1} (2^2-1)(2^4-1) = 2880\$.

Test cases

L => [n]
[2] => []
[2, 3] => [12]
[2, 3, 4] => [12]
[2, 3, 4, 7] => [12, 2880]
[3, 4, 7] => []
[3, 4, 5, 6, 7, 15] =>
 [218480640 = 2^14(2^3-1)(2^4-1)(2^7-1),
 223985664 = 2^14(2^3-1)(2^5-1)(2^6-1)]
[2, 3, 5, 7, 15] => [12] (suggested by Jonathan Allan)
(actual Mersenne exponents, truncated and 2 removed)
[3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607] =>
 [6086555670238378989670371734243169622657830773351885970528324860512791691264
 = 2^126(2^3-1)(2^5-1)(2^7-1)(2^19-1)(2^31-1)(2^61-1)]

Answer*

Draft saved
Draft discarded
Cancel

AltStyle によって変換されたページ (->オリジナル) /