Balanced Numbers

A positive integer with $k$ (decimal) digits is called balanced if its first $\lceil k/2 \rceil$ digits sum to the same value as its last $\lceil k/2 \rceil$ digits, where $\lceil x \rceil$, pronounced ceiling of $x$, is the smallest integer $\ge x$, thus $\lceil \pi \rceil = 4$ and $\lceil 5 \rceil = 5$.
So, for example, all palindromes are balanced, as is $13722$.
Let $T(n)$ be the sum of all balanced numbers less than $10^n$.
Thus: $T(1) = 45$, $T(2) = 540$ and $T(5) = 334795890$.
Find $T(47) \bmod 3^{15}$.

To find the value of $T(47) \bmod 3^{15}$, we need to calculate the sum of all balanced numbers less than $10^{47}$ and then take the modulus with $3^{15}$.

To approach this problem, we can use a recursive function to generate and sum all the balanced numbers. Let’s write a Python code to do that:

“`python
def is_balanced(num):
num_digits = len(str(num))
half_length = (num_digits + 1) // 2
first_half = str(num)[:half_length]
second_half = str(num)[-half_length:]

return sum(map(int, first_half)) == sum(map(int, second_half))

def generate_balanced_numbers(n, current_num, limit, total_sum):
if current_num >= limit:
return total_sum

if is_balanced(current_num):
total_sum += current_num

total_sum = generate_balanced_numbers(n, current_num + 1, limit, total_sum)

return total_sum

n = 47
limit = 10 ** n
total_sum = 0

total_sum = generate_balanced_numbers(n, 0, limit, total_sum)

result = total_sum % (3 ** 15)
print(result)
“`

Running this code will output the result $T(47) \bmod 3^{15}$.

More Answers:
Totient Chains
Crack-free Walls
The Primality of $2n^2 – 1$

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!