func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 10;   const int mod = 1e9 + 7;   const int AL = 9;   const int N = 5000;   const int INF = 1e9;   struct Trie {     int net[10000][12], fail[10000];     bool end[10000];     int root, L;     int newnode() {       for (int i = 0; i < AL; ++i) net[L][i] = -1;       end[L++] = false;       return L - 1;     }     void init() {       L = 0;       root = newnode();     }     void insert(char buf[]) {       int len = strlen(buf);       int now = root;       for (int i = 0; i < len; ++i) {         if (net[now][buf[i] -  1 ] == -1) net[now][buf[i] -  1 ] = newnode();         now = net[now][buf[i] -  1 ];       }       end[now] = true;     }     void build() {       queue<int> Q;       fail[root] = root;       for (int i = 0; i < AL; ++i)         if (net[root][i] == -1)           net[root][i] = root;         else {           fail[net[root][i]] = root;           Q.push(net[root][i]);         }       while (!Q.empty()) {         int now = Q.front();         Q.pop();         if (end[fail[now]]) end[now] = true;         for (int i = 0; i < AL; ++i) {           if (net[now][i] == -1)             net[now][i] = net[fail[now]][i];           else {             fail[net[now][i]] = net[fail[now]][i];             Q.push(net[now][i]);           }         }       }     }   } ac;   char ch[1010];   char cp[30];   int x;   int f[30];   void dfs(int num, int le) {     if (x < num) return;     if (x == num) {       f[0] = 0;       for (int i = (1); i < (le + 1); ++i) f[i] = f[i - 1] + cp[i - 1] -  0 ;       for (int i = (1); i < (le + 1); ++i)         for (int j = (i); j < (le + 1 - (i == 1)); ++j) {           if (f[le] % (f[j] - f[i - 1]) == 0) {             return;           }         }       ac.insert(cp);       return;     }     for (int i = (1); i < (10); ++i) {       cp[le] =  0  + i;       dfs(num + i, le + 1);       cp[le] =   0 ;     }   }   int main() {     scanf( %s , ch);     scanf( %d , &x);     ac.init();     dfs(0, 0);     ac.build();     int len = strlen(ch);     vector<vector<int> > dp(len + 1, vector<int>(ac.L, INF));     dp[0][0] = 0;     for (int i = (0); i < (len); ++i)       for (int j = (0); j < (ac.L); ++j)         if (dp[i][j] != INF) {           dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);           int nxt = ac.net[j][ch[i] -  1 ];           if (!ac.end[nxt]) dp[i + 1][nxt] = min(dp[i + 1][nxt], dp[i][j]);         }     printf( %d n , *min_element((dp[len]).begin(), (dp[len]).end()));     return 0;   }   