fork(36) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <algorithm>
  6. #include <utility>
  7. #include <set>
  8. #include <stack>
  9. #include <vector>
  10. #include <map>
  11. #include <queue>
  12.  
  13. #define MAX_N 100005
  14. #define MOD 1000000007
  15.  
  16. using namespace std;
  17.  
  18. inline long long int square(long long int x){ return ((x * x) % MOD); }
  19.  
  20. long long int fastexp(long long int b, long long int e){
  21. if(e == 0) return 1;
  22. if((e % 2) == 0) return (square(fastexp(b, e/2) % MOD) % MOD);
  23. return ((b * fastexp(b, e-1)) % MOD);
  24. }
  25.  
  26. char a[MAX_N];
  27. long long int k, s, tmp, r, t, pot, len, p1;
  28.  
  29. int main(){
  30.  
  31. scanf("%s", a);
  32. scanf("%I64d", &k);
  33.  
  34. s = 0;
  35. len = strlen(a);
  36. r = fastexp(2, len);
  37. t = ((1 - fastexp(r, k)) / (1 - r)) % MOD;
  38. pot = r / 2;
  39.  
  40. for(int i = len-1; i >= 0; i --){
  41. if(a[i] == '0' || a[i] == '5'){
  42. tmp = (pot * t) % MOD;
  43. s = (s + tmp) % MOD;
  44. }
  45. pot /= 2;
  46. }
  47.  
  48. printf("%I64d\n", s);
  49.  
  50. return 0;
  51. }
  52.  
Runtime error #stdin #stdout 0s 2992KB
stdin
Standard input is empty
stdout
Standard output is empty