首页 > 代码库 > Magic Five

Magic Five

技术分享
 1 #include<bits/stdc++.h>
 2 #include <cstdio>
 3 #include <iostream>
 4 #include <cstring>
 5 #include <vector>
 6 #define _xx ios_base::sync_with_stdio(0);cin.tie(0);
 7 #define INFS 0x3fffffff
 8 #define MAXN 1005
 9 using namespace std;
10 typedef long long ll;
11 string s;
12 ll k, p = 1000000007;
13 ll fastm(ll a, ll b)
14 {
15     ll ans = 1;
16     a %= p;
17     while(b)
18     {
19         if(b%2 == 1) ans = (ans*a)%p;
20         a *= a;
21         a %= p;
22         b /= 2;
23     }
24     return ans;
25 }
26 int main()
27 {_xx
28     while(cin >> s >> k)
29     {
30         ll q = fastm(2, s.size());
31         ll res = (fastm(q, k) - 1)*(fastm(q - 1, p - 2));
32         res %= p;
33         ll x = 1, ans = 0;
34         for(int i = 0; i < s.size(); i++, x = (x*2)%p)
35         {
36             if(s[i] == 5 || s[i] == 0)
37                 ans = (ans + x)%p;
38         }
39         cout << ans*res%p << endl;
40     }
41     return 0;
42 }
View Code

 

Magic Five