3546.Magic Five

Time Limit: 1s Memory Limit: 256MB

There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.

Now Iahub wants to count the number of ways he can obtain magic number, modulo 1000000007 (109+7). Two ways are different, if the set of deleted positions in s differs.

Look at the input part of the statement, s is given in a special form.

Input Format(From the terminal/stdin)

In the first line you're given a string a (1 \le |a| \le 105), containing digits only. In the second line you're given an integer k (1 \le k \le 109). The plate s is formed by concatenating k copies of a together. That is n=|a| \cdot k.

Output Format(To the terminal/stdout)

Print a single integer - the required number of ways modulo 1000000007 (109+7).

Sample Input 1

Copy
1256
1
    \n
 \n

Sample Output 1

Copy
4
 \n

Sample Input 2

Copy
13990
2
     \n
 \n

Sample Output 2

Copy
528
   \n

Sample Input 3

Copy
555
2
   \n
 \n

Sample Output 3

Copy
63
  \n

Hints

In the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.

In the second case, remember to concatenate the copies of a. The actual plate is 1399013990.

In the third case, except deleting all digits, any choice will do. Therefore there are 26-1=63 possible ways to delete digits.

Submit

请先 登录

© 2025 FAQs