#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long a, b, c, i, j, k, l, m, t, x, y, n, z;
  string s;
  map<long long, long long> mp;
  map<long long, long long>::iterator it;
  cin >> a >> s;
  n = s.size();
  long long a1[n + 1];
  a1[0] = 0;
  for (i = 1; i < n + 1; i++) a1[i] = s[i - 1] - '0' + a1[i - 1];
  for (i = 0; i < n + 1; i++) {
    for (j = i + 1; j < n + 1; j++) {
      mp[a1[j] - a1[i]]++;
    }
  }
  c = 0;
  if (!a) c = (mp[0] * (n * (n + 1) - mp[0]));
  if (!a) {
    cout << c << endl;
    return 0;
  }
  for (i = 0; i < n + 1; i++) {
    for (j = i + 1; j < n + 1; j++) {
      if (a1[j] - a1[i] != 0)
        if (a % (a1[j] - a1[i]) == 0) {
          it = mp.find(a / (a1[j] - a1[i]));
          if (it != mp.end()) c = c + mp[a / (a1[j] - a1[i])];
        }
    }
  }
  cout << c << endl;
  return 0;
}
