Josif_tepe

Untitled

Feb 18th, 2026
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. const long long MOD = 1e9 + 7;
  5. int to_int(string & s) {
  6.     int res = 0;
  7.     for(int i = 0; i < (int) s.size(); i++) {
  8.         res = (res * 10) + (s[i] - '0');
  9.     }
  10.     return res;
  11. }
  12. bool check(string & s) {
  13.     if((int) s.length() < 3) {
  14.         return (to_int(s) % 8 == 0);
  15.     }
  16.     else {
  17.         int x = (int) s.length();
  18.         int tmp = (s[x - 3] - '0') * 100 + (s[x - 2] - '0') * 10 + (s[x - 1] - '0');
  19.        
  20.         return (tmp % 8 == 0);
  21.     }
  22. }
  23. int main() {
  24.     int n;
  25.     cin >> n;
  26.    
  27.     string s;
  28.     cin >> s;
  29.    
  30.     long long res =0 ;
  31.     if(n <= 25) {
  32.         for(int bitmask = 0; bitmask < (1 << n); bitmask++) {
  33.             string tmp = "";
  34.             for(int i = 0; i < n; i++) {
  35.                 if(bitmask & (1 << i)) {
  36.                     tmp += s[i];
  37.                 }
  38.             }
  39.            
  40.            
  41.             if((int) tmp.length() > 0 and check(tmp)) {
  42.                 res++;
  43.                 res %= MOD;
  44.             }
  45.         }
  46.        
  47.     }
  48.     cout << res << endl;
  49.  
  50.     return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment