Showing posts with label length. Show all posts
Showing posts with label length. Show all posts

Sunday, 8 February 2026

The Revision Revisited

In my post titled A Revision, I outlined an alternative algorithm for building a sequence based on the factors of numbers considered with multiplicity. This is the algorithm:

Suppose we take any positive integer \(n \gt 1\) and apply the following rules to it:
  • if a \(4k+1\) prime, double it and add 1: \(n \rightarrow 2n+1\)
  • if a \(4k+3\) prime, subtract 1 and divide by 2: \(n \rightarrow (n-1)/2\)
  • if composite, determine its number of factors \(f\) counted \( \textbf{with multiplicity}\)
    • if \( n \pmod f \equiv 0\) then \(n \rightarrow \dfrac{n}{f} \)
    • if \( n \pmod f \not\equiv 0 \) then \(n \rightarrow n \times f\)
Keep repeating this process until a loop is reached or call a stop after a fixed number of iterations. 

What I'm interested in looking at in this post are the record lengths of sequences generated over a range of numbers, noting as well the highest and lowest values that are reached by sequence members. Figure 1 shows the results in the range from one to one million (permalink):


Figure 1

Let's now consider the algorithm where multiplicity is ignored. This algorithm in as follows:

Suppose we take any positive integer \(n \gt 1\) and apply the following rules to it:
  • if a \(4k+1\) prime, double it and add 1: \(n \rightarrow 2n+1\)
  • if a \(4k+3\) prime, subtract 1 and divide by 2: \(n \rightarrow (n-1)/2\)
  • if composite, determine its number of factors \(f\) counted \( \textbf{without multiplicity}\)
    • if \( n \pmod f \equiv 0\) then \(n \rightarrow \dfrac{n}{f} \)
    • if \( n \pmod f \not\equiv 0 \) then \(n \rightarrow n \times f\)
Keep repeating this process until a loop is reached or call a stop after a fixed number of iterations. 

Figure 2 shows the record lengths, highs and lows for the range from one to one million (permalink).


Figure 2

It can be noted that the record lengths of sequences are shorter when multiplicity is ignored and more end in 1 rather than a loop.

Friday, 6 February 2026

A Correction

After creating my post Number's Divisors to Sequence Algorithm, I was feeling satisfied. I'd gotten Gemini to create a neat little table for me. It showed the record lengths reached by numbers under the algorithm in the range up to one million but suffered from the fact that it was simply wrong. Here is the original table:

Number     | Length     | Status
-----------------------------------
2          | 5          | New Record!     
3          | 8          | New Record!     
6          | 10         | New Record!     
11         | 21         | New Record!     
22         | 23         | New Record!     
44         | 25         | New Record!     
50         | 28         | New Record!     
99         | 32         | New Record!     
125        | 33         | New Record!     
206        | 34         | New Record!     
350        | 37         | New Record!     
463        | 44         | New Record!     
487        | 46         | New Record!     
974        | 48         | New Record!     
1375       | 51         | New Record!     
1573       | 52         | New Record!     
1625       | 60         | New Record!     
5200       | 62         | New Record!     
14157      | 63         | New Record!     
16879      | 64         | New Record!     
18747      | 67         | New Record!     
39325      | 70         | New Record!     
89237      | 71         | New Record!     
151911     | 75         | New Record!     
563553     | 77         | New Record!     
803133     | 82         | New Record!  

Fortunately I spotted the problem when looking at the trajectory of the number associated with my diurnal age: 28068. It showed a length of 201, far in excess of the 82 associated with 803133. Furthermore, the algorithm only counted up to 201 and so the sequence was longer than that.

Naturally I confronted Gemini about the problem and here was its response:
The Reason for the DiscrepancyThe sequence for 28068 exhibits a behavior known as a Cunningham Chain.Your rule if is_prime: number = number * 2 + 1 matches the definition of a Cunningham Chain (where $p \to 2p+1$).If the sequence hits a "vein" of consecutive primes (e.g., a chain of 40 primes), the number grows by a factor of $2^{40}$ (approx. 1 trillion). My previous Python code had a safety brake: if number > \(10^12\): break. 28068 likely skyrockets past  one trillion ($10^{12}$) very quickly. My code hit this safety limit and stopped counting, reporting a truncated (incorrect) length.
Gemini proposed modifications to the code but these overtaxed the Jupyter notebook and it got stuck at a point shown in Figure 1.


Figure 1

Eventually I decided to get Gemini to write the code for just a single number as input and not a range. Even this proved too much for the Jupyter notebook. I don't know whether the sequence for 28068 goes on forever or not but I do know that the original algorithm that Gemini provided me with was flawed. It was only by chance that I found this out so caution is advised in accepting anything Gemini offers up. I've commented in the past on its coding limitations.

The failure of the algorithm to reach completion is attributed to Cunningham chains so I'd thought I'd better look back at that topic. It turns out that the longest known Cunningham chain of the first kind (\(2p+1\) is 17 primes long so why does Gemini mention chains of 40 primes when none are known? Nonetheless, it's likely that the \(2p+1\) rule that I'm applying to prime numbers does lead quickly to very large number. My choice of this rule was quite arbitrary. Given that \(4k+1\) and \(4k-1\) primes are pretty much in equal abundance, I could apply an alternative rule such as the following to a prime \(p\):
  • if \(p \pmod 4 \equiv 1\) then \(p \rightarrow 2 \times p +1 \)
  • if \(p \pmod 4 \equiv 3\) then \(p \rightarrow (p -1 )/2 \)
This should keep the progressive numbers from growing too large. I should do this with the factors as well (see earlier posts Number's Factors to Sequence Algorithm 1 and Number's Factors to Sequence Algorithm 2). Figure 2 shows the record breaking numbers under these new rules (up to one million).


Figure 2: permalink

In summary, the record breaking numbers are 1, 2, 4, 13, 17, 34, 50, 98, 294, 650, 722, 2166, 4751, 5313, 9502, 11979, 19773, 46137, 125229, 257049, 385573, 714025.

I also got Gemini to write the code for the input of a single number and the trajectory of the number as output. Let's use 28068 as an example. Figure 2 shows the output.


Figure 3: permalink

ADDENDUM on 16th of February 2026:

It appears that this latest program to determine the record lengths under the new algorithm is faulty. If 28077 is entered the program crashes because the numbers become too large. I confronted Gemini with this discovery and it pointed out that number size is capped at $10^{25}$) and some sequences explode so quickly that they exceed the number cap before they reach a record length. Gemini modified the product to detect numbers leading to these exploding sequences. There are quite a few. Figure 4 shows the 27 of them in the range from 28004 to 28449. This gives some idea of their frequency (27 out 445 or a little over 6%).


Figure 4: permalink

Wednesday, 28 January 2026

Number's Divisors to Sequence Algorithm

A logical progression to looking at the sequence produced by considering the factors of a number (see Number's Factors to Sequence Algorithm 1 and Number's Factors to Sequence Algorithm 2) is to consider the sequence formed by its divisors. The rules this time around are very similar to that for factors except that we are dealing now with the number's divisors.

 Suppose we take any positive integer \(n \gt 1\) 
  • if prime, double it and add 1: \(n \rightarrow 2n+1\)
  • if composite, determine its number of divisors \(d\)
  • if \( n \pmod d \equiv 0\) then \(n \rightarrow \dfrac{n}{d} \)
  • if \( n \pmod d \not\equiv 0 \) then \(n \rightarrow n \times d\)
Keep repeating this process until a loop is reached or call a stop after a fixed number of iterations. 

Let's use 28059 as an example. Applying the above rules leads to the following sequence:

28059, 224472, 7183104, 517183488, 2693664, 37412, 448944, 17957760, 140295, 2244720, 28059

We end up right where we started. Here the details with number of divisors shown (permalink):
28059 --> 8
224472 --> 32
7183104 --> 72
517183488 --> 192
2693664 --> 72
37412 --> 12
448944 --> 40
17957760 --> 128
140295 --> 16
2244720 --> 80
28059 --> 8
As before we are interested in record lengths and my algorithm was not up to the job of determing these so I had to call on Gemini for help. It came up with the following record breaking numbers in the range up to one million (permalink). This algorithm proved to be faulty. For the correction see blog post titled "A Correction".

2, 3, 6, 11, 22, 44, 50, 99, 125, 206, 350, 463, 487, 974, 1375, 1573, 1625, 5200, 14157, 16879, 18747, 39325, 89237, 151911, 563553, 803133

Here are the details of the lengths:

Number     | Length     | Status
-----------------------------------
2          | 5          | New Record!     
3          | 8          | New Record!     
6          | 10         | New Record!     
11         | 21         | New Record!     
22         | 23         | New Record!     
44         | 25         | New Record!     
50         | 28         | New Record!     
99         | 32         | New Record!     
125        | 33         | New Record!     
206        | 34         | New Record!     
350        | 37         | New Record!     
463        | 44         | New Record!     
487        | 46         | New Record!     
974        | 48         | New Record!     
1375       | 51         | New Record!     
1573       | 52         | New Record!     
1625       | 60         | New Record!     
5200       | 62         | New Record!     
14157      | 63         | New Record!     
16879      | 64         | New Record!     
18747      | 67         | New Record!     
39325      | 70         | New Record!     
89237      | 71         | New Record!     
151911     | 75         | New Record!     
563553     | 77         | New Record!     
803133     | 82         | New Record!  

Let's look at the sequence for the last number in the above list, 803133 (permalink):

803133, 4818798, 77100768, 1606266, 19275192, 616806144, 8566752, 356948, 2141688, 34267008, 1070844, 89237, 178475, 3212550, 346955400, 149884732800, 115651800, 321255, 11565180, 64251, 1156518, 69391080, 19984631040, 23130360, 5551286400, 6425100, 1040866200, 524596564800, 231303600, 514008, 7139, 42834, 1028016, 92521440, 257004, 13878216, 1998463104, 5204331, 218581902, 41967725184, 48573756, 10491931296, 16191252, 2914425360, 3469554, 249807888, 59953893120, 61680960, 20724802560, 15700608, 4019355648, 7850304, 35046, 1121472, 125604864, 356832, 3717, 44604, 2140992, 299738880, 555072, 6608, 132160, 2360, 37760, 1180, 14160, 354, 2832, 56640, 3171840, 19824, 792960, 6195, 99120, 1239, 9912, 317184, 22837248, 118944, 1652, 19824

Like the previous sequences using the number of factors, this sequence using the number of divisors is also \( \textbf{base independent}\).

Number's Factors to Sequence Algorithm 2

 Suppose we take any positive integer \(n \gt 1\) and apply the following rules to it:

  • if prime, double it and add 1: \(n \rightarrow 2n+1\)
  • if composite, determine its number of factors \(f\) counted \( \textbf{without} \) multiplicity
  • if \( n \pmod f \equiv 0\) then \(n \rightarrow \dfrac{n}{f} \)
  • if \( n \pmod f \not\equiv 0 \) then \(n \rightarrow n \times f\)

Keep repeating this process until a loop is reached or call a stop after a fixed number of iterations. This process is exactly the same as in my previous post except that the number of factors is counted without multiplicity. Let's apply this algorithm to 28059. The result is the sequence 28059, 9353, 18706, 56118, 224472, 56118. Here are the details (permalink):

  • \(28059 = 3 \times 47 \times 199\) with three factors
    3 divides 28059 to give 9353

  • \(9353 = 47 \times 199\) with two factors but 2 doesn't divide 9353
    multiplying by 2 gives 18706

  • \(18706 = 2 \times 47 \times 199\) with three factors but 3 doesn't divide 18706
    multiplying by 3 gives 56118

  • \(56118 = 2 \times 3 \times 47 \times 199\) with four factors but 4 doesn't divide 56118
    multiplying by 4 gives 224472

  • \(224472 = 2^3 \times 3 \times 47 \times 199\) with four distinct prime factors
    4 divided into 224472 gives 56118

  • \(56118\) occurred earlier in the sequence and so we have a loop
The fluctuations between terms are less extreme and the record breaking numbers this time around are 2, 3, 6, 12, 24, 31, 62, 93, 139, 278, 417, 1251, 3753, 8896, 17792, 18433, 36866, 55299, 165897, 248851, 497702, 746553.

Here are the sequence lengths of these record breakers (permalink) up to one million:

2 --> 10
3 --> 14
6 --> 15
12 --> 16
24 --> 17
31 --> 18
62 --> 19
93 --> 21
139 --> 23
278 --> 24
417 --> 26
1251 --> 27
3753 --> 28
8896 --> 29
17792 --> 30
18433 --> 31
36866 --> 32
55299 --> 34
165897 --> 35
248851 --> 37
497702 --> 38
746553 --> 40

When the algorithm ran with multiplicity of factors being counted, the maximum sequence length up to one million was 155. The trajectory of the last number in the previous list (746553) is as follows:

746553, 1493106, 497702, 248851, 497703, 995406, 331802, 165901, 331803, 663606, 221202, 73734, 24578, 12289, 24579, 49158, 16386, 5462, 2731, 5463, 10926, 3642, 1214, 607, 1215, 2430, 810, 270, 90, 30, 10, 5, 11, 23, 47, 95, 190, 570, 2280, 570

Figure 1 shows a graph of the trajectory of 746553 using a logarithmic \(y\) scale.


Figure 1

Wednesday, 2 July 2025

Prime Factor Sequences

I'm surprised I've not come across this type of sequence before. It has two variants and they are generated iteratively as follows:

  • number --> sum of prime factors without multiplicity
    For example, 24 with factors of 2 and 3 gives 5 and terminates after just one step

  • number --> sum of prime factors with multiplicity
    For example, 24 with factors of 2, 2, 2 and 3 gives 11 and terminates after just one step
Larger numbers of course take more than one step to terminate and it's of interest to consider those numbers that set records in term of trajectory lengths. In this context, let's consider OEIS A047830.


A047830  least number which becomes prime after exactly \(n\) iterations of f(\(x\)) = sum of prime factors of \(x\).


The members of this sequence are 4, 14, 26, 62, 134, 393, 1774, 13682, 41037 up to 100,000. The trajectories are shown in Figure 1 with length indicating the number of steps or iterations:


Figure 1: permalink

If the sum of prime factors with multiplicity is considered then we get OEIS A121360 with sequence members 1, 8, 14, 26, 62, 134, 393, 1257, 4659, 9314, 27933 up to 100,000. The trajectories are shown in Figure 2 with length indicating the number of steps or iterations:



Figure 2: permalink

The algorithms used to find the trajectories of record lengths can be easily modified to find numbers with trajectories of a specified length (number of steps or iterations). For example, how many numbers in the range up to 40000 require eight steps to reach a prime under the sum of prime factors without multiplicity algorithm. Here are the numbers (with 13682 being the first as we know already from Figure 1):

13682, 18002, 19137, 22934, 24014, 24787, 27364, 27849, 30062, 30993, 32577, 33477, 35410, 35798, 36004, 36398, 36706, 39206

These numbers are the initial members of OEIS A047827. Figure 3 shows the details of their trajectories:


Figure 3: permalink