Convert a number to another by dividing by its factor or removing first occurrence of a digit from an array

  #include using namespace std;  int isPresent(int n, int x){        string num = to_string(n);          for (int i = 0; i < num.size();         i++) {                          if ((num[i] - '0') == x)            return i;    }    return -1;}  int removeDigit(int n, int index){        string num = to_string(n);          string ans = "";          for (int i = 0;         i < num.size(); i++) {        if (i != index)            ans += num[i];    }              if (ans == "" || (ans.size() == 1                      && ans[0] == '0'))        return -1;          int x = stoi(ans);    return x;}  bool reduceNtoX(int a, int b,                int d[], int n){        queue q;          q.push(a);              unordered_map visited;          visited[a] = true;          while (!q.empty()) {                          int top = q.front();        q.pop();          if (top < 0)            continue;                          if (top == b)            return true;                  for (int i = 0; i < n; i++) {                                                  if (d[i] != 0 && top % d[i] == 0                && !visited[top / d[i]]) {                  q.push(top / d[i]);                visited[top / d[i]] = true;            }                          int index = isPresent(top, d[i]);            if (index != -1) {                                                                  int newElement                    = removeDigit(top, index);                                  if (newElement != -1                    && (!visited[newElement])) {                    q.push(newElement);                    visited[newElement] = true;                }            }        }    }              return false;}  int main(){      int A = 5643, B = 81;    int D[] = { 3, 8, 1 };    int N = sizeof(D) / sizeof(D[0]);      if (reduceNtoX(A, B, D, N))        cout