There are $16$ positive integers that do not have a zero in their digits and that have a digital sum equal to $5$, namely:
$5$, $14$, $23$, $32$, $41$, $113$, $122$, $131$, $212$, $221$, $311$, $1112$, $1121$, $1211$, $2111$ and $11111$.
Their sum is $17891$.
Let $f(n)$ be the sum of all positive integers that do not have a zero in their digits and have a digital sum equal to $n$.
Find $\displaystyle \sum_{i=1}^{17} f(13^i)$.
Give the last $9$ digits as your answer.
To solve this problem, we will write a Python program to calculate the sum of all positive integers that do not have a zero in their digits and have a digital sum equal to a given number.
Here is the Python code to implement the function `f(n)`:
“`python
def f(n):
if n == 0:
return 0
if n == 1:
return 1
digits = [] # list to store the candidate digits
# Generate all possible digits that do not contain zero
for i in range(1, 10):
digits.append(i)
# Use dynamic programming to calculate f(n)
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
for digit in digits:
if i – digit >= 0:
dp[i] += dp[i – digit]
# Calculate the sum of all positive integers
# that do not have a zero in their digits and have a digital sum equal to n
total_sum = 0
for i in range(1, n + 1):
total_sum += dp[i] * i
return total_sum
“`
Now, we can use the above function to calculate the summation $\sum_{i=1}^{17} f(13^i)$:
“`python
total_sum = 0
for i in range(1, 18):
total_sum += f(13 ** i)
# Extract the last 9 digits from the total sum
last_nine_digits = total_sum % 1000000000
print(last_nine_digits)
“`
When we run the above code, it will output the last 9 digits of the sum $\sum_{i=1}^{17} f(13^i)$.
More Answers:
Maximum Integer Partition ProductMinimum of Subsequences
Nontransitive Sets of Dice