这倒题找出规律不难,关键是有mod运算,还要求等比数列,直接用公式求,存在除法,不行,所以采用二分的方式。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
typedef long long LL;
using namespace std;
const int maxn = 500 + 5;
const int Mod = 1000000000 + 7;
string s;
LL k,q;
LL power(LL x,LL num){
if(num == 0) return 1;
if(num == 1) return x;
LL tem = power(x,num/2);
if(num % 2 == 1) return ((tem * tem) % Mod * x) % Mod;
else return (tem * tem) % Mod;
}
LL sum(LL x){
if(x == 1) return 1;
LL tem = sum(x/2);
if(x%2 == 1) return ((tem * (1 + power(q,x/2))) % Mod + power(q,x-1)) % Mod;
else return (tem * (1 + power(q,x/2))) % Mod;
}
int main(){
while(cin >> s >> k){
LL a = 0;
LL n = s.length();
for(int i = 0;i < n;i++){
if(s[i] == '0' || s[i] == '5'){
a = (a + power(2,i)) % Mod;
}
}
q = power(2,n);
cout << (a * sum(k)) % Mod << endl;
}
return 0;
}