Sequences with Nice Divisibility Properties

Let $Seq(n,k)$ be the number of positive-integer sequences $\{a_i\}_{1 \le i \le n}$ of length $n$ such that:
$n$ is divisible by $a_i$ for $1 \le i \le n$, and
$n + a_1 + a_2 + \cdots + a_n$ is divisible by $k$.
Examples:
$Seq(3,4) = 4$, and the $4$ sequences are:
$\{1, 1, 3\}$
$\{1, 3, 1\}$
$\{3, 1, 1\}$
$\{3, 3, 3\}$
$Seq(4,11) = 8$, and the $8$ sequences are:
$\{1, 1, 1, 4\}$
$\{1, 1, 4, 1\}$
$\{1, 4, 1, 1\}$
$\{4, 1, 1, 1\}$
$\{2, 2, 2, 1\}$
$\{2, 2, 1, 2\}$
$\{2, 1, 2, 2\}$
$\{1, 2, 2, 2\}$
The last nine digits of $Seq(1111,24)$ are $840643584$.
Find the last nine digits of $Seq(1234567898765,4321)$.

To solve this problem, we need to generate the Tribonacci sequence, update the array according to the given rules, calculate the maximum sum of subarrays after each step, and finally compute the sum of these maximum subarrays up to a certain step.

Let’s start by generating the Tribonacci sequence:

“`python
def generate_tribonacci(n):
tribonacci = [0, 0, 1] # Starting values for t0, t1, t2

for i in range(3, n+1):
tribonacci.append(tribonacci[i-1] + tribonacci[i-2] + tribonacci[i-3])

return tribonacci
“`

Next, we can define the function to update the array `A_n` and calculate the maximum sum of any contiguous subarray after each step:

“`python
def update_array(n, steps):
tribonacci = generate_tribonacci(2*steps) # Generate Tribonacci sequence up to 2*steps for indexing
A_n = [0] * n
M_n = [0] * (steps+1)
max_sum = 0

for i in range(1, steps+1):
idx = tribonacci[2*i-2] % n
A_n[idx] += 2 * (tribonacci[2*i-1] % n) – n + 1

max_sum += max(A_n)
M_n[i] = max_sum

return M_n
“`

Finally, we can calculate the desired difference between `S(10,000,003, 10,200,000)` and `S(10,000,003, 10,000,000)`:

“`python
S_10_200_000 = update_array(10_000_003, 10_200_000)
S_10_000_000 = update_array(10_000_003, 10_000_000)
difference = S_10_200_000[-1] – S_10_000_000[-1]

print(difference)
“`

Running the above code will output the desired difference between `S(10,000,003, 10,200,000)` and `S(10,000,003, 10,000,000)`.

More Answers:
Shortest Lattice Vector
Divisor Nim
Tangent Circles

Error 403 The request cannot be completed because you have exceeded your quota. : quotaExceeded

Share:

Recent Posts

Don't Miss Out! Sign Up Now!

Sign up now to get started for free!