#P10167. [DTCPC 2024] 小方学乘法
[DTCPC 2024] 小方学乘法
Background
Xiao Fang was in a math class and started learning multiplication, but he fell asleep in class.
Problem Description
He dreamed of a math formula that only contained digits and multiplication signs. Because the dream was blurry, he might have mistaken the multiplication sign for the letter .
Somehow he remembered the value of this , and he believed that letters can be treated as digits. So, after replacing all letters with digits, he computed the value of the expression.
Then he was caught sleeping by the coach.
Before being ganked, he wanted to recall the value he computed in the dream.
But Xiao Fang was too sleepy, so he decided to compute the value in all cases: that is, for each multiplication sign, replace it or do not replace it with the value represented by the letter , and sum the values over all possible cases.
However, Xiao Fang even forgot itself. He only remembers that it is within some range , so for each he needs to compute the sum described above, and then sum those results again.
Xiao Fang just learned multiplication and cannot handle very large numbers, so he wants you to output the answer .
Formal statement
You are given a string that contains only digits and ?. It is guaranteed that there are no two adjacent ?, and the first and last characters of the string are not ?.
Now each ? can be replaced by or , where is a given string-concatenation variable.
For example, for 12x45, when , the replacement result is 123345.
Let the sum of the weights of the expression over all replacement schemes of ? when be .
Compute .
Input Format
The first line contains a string of length (), representing the expression.
The second line contains two positive integers ().
Output Format
Output one positive integer, the answer modulo .
123?13?23
1 10
507086689
Hint
Translated by ChatGPT 5