Infinite String Tour

Create a sequence of numbers using the “Blum Blum Shub” pseudo-random number generator:

\begin{align}
s_0 &= 14025256\\
s_{n + 1} &= s_n^2 \bmod 20300713
\end{align}

Concatenate these numbers $s_0s_1s_2\cdots$ to create a string $w$ of infinite length.
Then, $w = {\color{blue}14025256741014958470038053646\cdots}$
For a positive integer $k$, if no substring of $w$ exists with a sum of digits equal to $k$, $p(k)$ is defined to be zero. If at least one substring of $w$ exists with a sum of digits equal to $k$, we define $p(k) = z$, where $z$ is the starting position of the earliest such substring.
For instance:
The substrings $\color{blue}1, 14, 1402, \dots$
with respective sums of digits equal to $1, 5, 7, \dots$
start at position $\mathbf 1$, hence $p(1) = p(5) = p(7) = \cdots = \mathbf 1$.
The substrings $\color{blue}4, 402, 4025, \dots$
with respective sums of digits equal to $4, 6, 11, \dots$
start at position $\mathbf 2$, hence $p(4) = p(6) = p(11) = \cdots = \mathbf 2$.
The substrings $\color{blue}02, 0252, \dots$
with respective sums of digits equal to $2, 9, \dots$
start at position $\mathbf 3$, hence $p(2) = p(9) = \cdots = \mathbf 3$.
Note that substring $\color{blue}025$ starting at position $\mathbf 3$, has a sum of digits equal to $7$, but there was an earlier substring (starting at position $\mathbf 1$) with a sum of digits equal to $7$, so $p(7) = 1$, not $3$.
We can verify that, for $0 \lt k \le 10^3$, $\sum p(k) = 4742$.
Find $\sum p(k)$, for $0 \lt k \le 2 \times 10^{15}$.

To solve this problem, we need to implement the “Blum Blum Shub” pseudo-random number generator and then process the generated sequence according to the given rules to calculate the values of p(k). Finally, we will find the sum of all p(k) values for 0 < k <= 2 * 10^15.

Here is the Python code to solve the problem:

“`python
def blum_blum_shub_sequence():
s = 14025256
while True:
yield s
s = (s ** 2) % 20300713

def sum_of_digits(n):
return sum(int(d) for d in str(n))

def find_p():
sequence = blum_blum_shub_sequence()
p_values = [0] * 10
found_p = set()
for position, num in enumerate(sequence, start=1):
current_sum = sum_of_digits(num)
if current_sum in found_p:
continue
found_p.add(current_sum)
p_values[current_sum] = position
if len(found_p) == 10:
break
return p_values

def calculate_sum_of_p(limit):
p_values = find_p()
sum_of_p = sum(p_values[k] for k in range(1, 10))
current_position = p_values[1]
while current_position <= limit: current_position += p_values[1] sum_of_p += current_position return sum_of_p limit = 2 * 10**15 result = calculate_sum_of_p(limit) print(result) ``` The code first defines a generator function `blum_blum_shub_sequence()` that generates the sequence of numbers using the "Blum Blum Shub" pseudo-random number generator. It starts with s0 = 14025256 and uses the specified formula to generate the subsequent numbers. Next, the function `sum_of_digits(n)` is defined to calculate the sum of digits of a given number. The function `find_p()` iterates over the generated sequence and keeps track of the earliest positions (`p_values`) where a sum of digits equal to k is found. It uses a set (`found_p`) to avoid duplicate calculations and stops once all 10 different sums of digits from 1 to 9 are found. The main function `calculate_sum_of_p(limit)` first calls `find_p()` to get the initial p-values. It then calculates the sum of p(k) for 1 <= k <= 9 and initializes `current_position` with the starting position of p(1). It continues to increment `current_position` by p(1) until `current_position` exceeds the given limit. The final result is the sum of all p(k) values. Finally, we set the limit to 2 * 10^15 and print the result obtained from `calculate_sum_of_p(limit)`.

More Answers:
An Arithmetic Geometric Sequence
Luxury Hampers
Tours on a $4 \times N$ Playing Board

Share:

Recent Posts

Mathematics in Cancer Treatment

How Mathematics is Transforming Cancer Treatment Mathematics plays an increasingly vital role in the fight against cancer mesothelioma. From optimizing drug delivery systems to personalizing

Read More »