#include <bits/stdc++.h>
using namespace std;
long long int num[40000];
int main(void) {
  int a;
  string s;
  cin >> a >> s;
  int n = s.size();
  int ar[n];
  for (int i = 0; i < n; ++i) {
    ar[i] = (int)s[i] - 48;
  }
  int pref[n];
  long long int counts = 0;
  pref[0] = ar[0];
  for (int i = 1; i < n; ++i) {
    pref[i] = pref[i - 1] + ar[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      int val = pref[j] - pref[i] + ar[i];
      ++num[val];
    }
  }
  for (int i = 1; i < 40000; ++i) {
    if (i > a) {
      break;
    }
    if (a % i == 0) {
      if (a / i < 40000) counts += 1LL * num[i] * num[a / i];
    }
  }
  if (a == 0) {
    long long int size = n;
    counts = num[0] * size * (size + 1) - num[0] * num[0];
  }
  cout << counts << '\n';
}
