func_code_string: #include <bits/stdc++.h>   char s[1005];   int a[25], mark[6071], dp[1005][6071], ch[6071][12], link[6071], tl, ans = 1e9,                                                                        x, n;   void insert(int len) {     int rt = 0;     for (int i = 1; i <= len; ++i) {       if (!ch[rt][a[i]]) ch[rt][a[i]] = ++tl;       rt = ch[rt][a[i]];     }     mark[rt] = 1;   }   void build() {     std::queue<int> q;     std::memset(link, -1, sizeof(link));     link[0] = 0;     for (int i = 0; i < 10; ++i)       if (ch[0][i]) {         q.push(ch[0][i]);         link[ch[0][i]] = 0;       }     while (!q.empty()) {       int u = q.front();       q.pop();       mark[u] |= mark[link[u]];       for (int i = 0; i < 10; ++i) {         if (ch[u][i]) {           mark[ch[u][i]] |= mark[u];           link[ch[u][i]] = ch[link[u]][i];           q.push(ch[u][i]);         } else           ch[u][i] = ch[link[u]][i];       }     }   }   void dfs(int u, int sum) {     if (sum == x) {       for (int l = 1; l < u; ++l) {         int s = 0;         for (int r = l; r < u; ++r) {           s += a[r];           if (s != x && x % s == 0) return;         }       }       insert(u - 1);       return;     }     for (int j = 1; sum + j <= x && j < 10; ++j) {       a[u] = j;       dfs(u + 1, sum + j);     }   }   void generate() {     dfs(1, 0);     build();   }   int main() {     scanf( %s%d , s + 1, &x);     n = std::strlen(s + 1);     generate();     std::memset(dp, 63, sizeof(dp));     dp[1][0] = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= tl; ++j) {         if (!mark[ch[j][s[i] -  0 ]])           dp[i + 1][ch[j][s[i] -  0 ]] =               std::min(dp[i + 1][ch[j][s[i] -  0 ]], dp[i][j]);         dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + 1);       }     }     for (int j = 0; j <= tl; ++j) ans = std::min(ans, dp[n + 1][j]);     printf( %d , ans);     return 0;   }   