Magic Five

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

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

Output

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

Examples

Input

1256
1

Output

4

Input

13990
2

Output

528

Input

555
2

Output

63

Note

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.

这个东西是有规律的,多写写就能看出来,是一个等比数列,然后写出来首项,公比之类的就出来了。

#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;
const ll maxn=1000000007;
long long quick(ll a,ll b,ll c){
    long long ans=1;
    a=a%c;
    while(b!=0){
        if(b&1) ans=(ans*a)%c;
        b>>=1;
        a=(a*a)%c;
    }
    return ans;
}
int main(){
    string str;
    long long k,len;
    long long sum=0,z,m,temp;

    cin>>str>>k;
    len=str.length();
    z=1-quick(2, len*k, maxn);
    m=1-quick(2, len, maxn);
    temp=(z*quick(m, maxn-2, maxn))%maxn;
    for(int i=0;i<len;i++){
        if(str[i]=='0'||str[i]=='5'){
            sum=(sum%maxn+(quick(2, i, maxn)*temp)%maxn)%maxn;
        }
    }
    printf("%lld\n",sum%maxn);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值