首页 > 代码库 > 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 }
Magic Five
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。