func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long power(long long a, long long b, long long md) {     return (!b ? 1                : (b & 1 ? a * power(a * a % md, b / 2, md) % md                         : power(a * a % md, b / 2, md) % md));   }   const int xn = 1e3 + 10;   const int xm = 2e4 + 10;   const int sq = 300;   const int inf = 1e9 + 10;   const long long INF = 1e18 + 10;   const int mod = 1e6 + 7;   const int base = 257;   const int SIG = 26;   int n, k, tb[1 << 20], dp[xn][xm], ptr, a[xm], C[xm][SIG], ans = inf;   string S;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> S >> k, n = int(S.size());     if (k == 1) {       ans = 0;       for (int i = 0; i < n; ++i) ans += (S[i] ==  1 );       return cout << ans <<   n , 0;     }     for (int mask = 0; mask < (1 << k); ++mask) {       bool flag = true;       for (int i = 0; i < k; ++i)         flag &= (!((mask & (1 << i))) | !(mask & (1 << (i + 1))));       flag &= !(mask & 1), flag &= !(mask & 2);       if (flag) tb[mask] = ptr, a[ptr++] = mask;     }     for (int t = 0; t < ptr; ++t) {       int mask = a[t] + 1;       for (int i = 2; i < 10; ++i) {         for (int bit = i; bit <= k; ++bit)           if ((mask & (1 << (bit - i)))) C[t][i] += (1 << bit);         bool flag = !(C[t][i] & (1 << k));         for (int j = 1; j < k; ++j)           if (k % j == 0) flag |= (C[t][i] & (1 << j));         for (int b1 = 2; b1 < k; ++b1)           for (int b2 = b1 + 1; b2 <= k; ++b2)             if ((C[t][i] & (1 << b1)) && (C[t][i] & (1 << b2)))               flag |= (k % (b2 - b1) == 0);         C[t][i] = (C[t][i] & (C[t][i] ^ (1 << k)));         if (!flag) C[t][i] = -1;       }     }     for (int i = 0; i < xn; ++i)       for (int j = 0; j < ptr; ++j) dp[i][j] = inf;     dp[0][0] = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < ptr; ++j) {         int mask = a[j];         if (S[i] ==  1 )           dp[i + 1][0] = min(dp[i + 1][0], dp[i][j]);         else {           dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);           int x = C[j][S[i] -  0 ];           if (x != -1) dp[i + 1][tb[x]] = min(dp[i + 1][tb[x]], dp[i][j]);         }       }     }     for (int i = 0; i < ptr; ++i) ans = min(ans, dp[n][i]);     cout << ans <<   n ;     return 0;   }   