func_code_string: #include <bits/stdc++.h>   using namespace std;   void chmax(int& a, int b) { a = max(a, b); }   void chmin(int& a, int b) { a = min(a, b); }   int nth_bit(int64_t num, int n) { return (num >> n) & 1; }   int main() {     string S;     int X;     cin >> S >> X;     int N = S.size();     vector<int> A(N);     for (int i = 0; i < N; i++) A[i] = S[i] -  0 ;     vector<int> ds;     for (int i = 1; i < X; i++)       if (X % i == 0) ds.push_back(i);     if (X == 1) {       cout << count(A.begin(), A.end(), 1) << endl;       return 0;     }     int B = 1 << (X + 1);     vector<int> valid;     for (int b = 0; b < B; b++) {       bool ok = true;       for (int i = 0; i < X; i++)         if (nth_bit(b, i) && nth_bit(b, i + 1)) ok = false;       if (ok) valid.push_back(b);     }     vector<bool> ok(B);     for (int b = 0; b < B; b++) {       if (nth_bit(b, X) == 0) ok[b] = true;       for (int d : ds)         for (int i = 0; i < X; i++)           if (nth_bit(b, i) && nth_bit(b, i + d)) ok[b] = true;     }     vector<int> dp(B), dp2(B);     auto solve = [&](vector<int>& V) -> int {       int N = V.size();       for (int b : valid) dp[b] = 1e9;       dp[1] = 0;       for (int i = 0; i < N; i++) {         for (int b : valid) dp2[b] = dp[b] + 1;         for (int b : valid) {           int b2 = ((b << V[i]) | 1) & (B - 1);           if (ok[b2]) chmin(dp2[b2], dp[b]);         }         for (int b : valid) dp[b] = dp2[b];       }       int ans = 1e9;       for (int b : valid) chmin(ans, dp[b]);       return ans;     };     int ans = 0;     vector<int> V;     for (int i = 0; i < N; i++) {       if (A[i] == 1) {         if (V.size()) ans += solve(V);         V.clear();       } else {         V.push_back(A[i]);       }     }     if (V.size()) ans += solve(V);     cout << ans << endl;     return 0;   }   