#include <bits/stdc++.h>
using namespace std;
long long nar[4009];
long long pf[4009];
long long mp[40000];
int main() {
  long long a;
  string s;
  cin >> a >> s;
  long long m = s.length();
  for (long long i = 0; i < m; i++) nar[i] = s[i] - '0';
  pf[0] = 0;
  for (long long i = 0; i < m; i++) pf[i + 1] = pf[i] + nar[i];
  for (long long i = 0; i <= m; i++)
    for (long long j = i + 1; j <= m; j++) mp[pf[j] - pf[i]]++;
  long long sm = 0;
  if (a != 0) {
    for (long long i = 0; i <= m; i++)
      for (long long j = i + 1; j <= m; j++)
        if (pf[j] - pf[i] != 0 && a % (pf[j] - pf[i]) == 0 &&
            a / (pf[j] - pf[i]) < 40000)
          sm += mp[a / (pf[j] - pf[i])];
  } else {
    long long tsm = (m + 1) * m / 2;
    long long zrc = 0;
    for (long long i = 0; i <= m; i++)
      for (long long j = i + 1; j <= m; j++)
        if (pf[j] - pf[i] == 0) zrc++;
    sm = zrc * tsm + zrc * tsm - zrc * zrc;
  }
  cout << sm << endl;
  return 0;
}
