Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

77%
+5 −0
#1: Initial revision by user avatar wizzwizz4‭ · 2021-08-14T16:20:46Z (over 3 years ago)
Finding the smallest Mersenne-number multiple of an odd integer
### Problem
Given an odd integer $a$, there exists some smallest $b$ such that $a\times b = 2^n-1$ (for some $n$). Find $b$ and $n$.

  * What is an upper bound for this problem?
  * What is a lower bound for this problem?
  * In what cases is it easier?

## Naïve algorithm

I know I can count up all $n$ from $\lceil \log_2 a \rceil$ until I find $2^n-1 = 0 \mod a$:

```
assert is_odd(a)
for n := ceil(log₂(a)) to infinity:
    b := ((2^n)-1) / a
    if is_integer(b):
        return b, n
```

If $n < a$ (which might be true), my naïve algorithm is $O(n)$.

## Table

|  $a$ |       $b$ |  $n$ |
| ----:| ---------:| ----:|
|  $1$ |       $1$ |  $1$ |
|  $3$ |       $1$ |  $2$ |
|  $5$ |       $3$ |  $4$ |
|  $7$ |       $1$ |  $3$ |
| $11$ |      $93$ | $10$ |
| $13$ |     $315$ | $12$ |
| $15$ |       $1$ |  $4$ |
| $17$ |      $15$ |  $8$ |
| $19$ |   $13797$ | $18$ |
| $21$ |       $3$ |  $6$ |
| $23$ |      $89$ | $11$ |
| $25$ |   $41943$ | $20$ |
| $27$ |    $9709$ | $18$ |
| $29$ | $9256395$ | $28$ |
| $31$ |       $1$ |  $5$ |
| $33$ |      $31$ | $10$ |