#include <bits/stdc++.h>
using namespace std;
long long ok[111111], l = 0ll;
int a, n, b[4444];
char s[4444];
int main() {
  cin >> a >> s;
  n = strlen(s);
  b[0] = 0;
  b[1] = s[0] - '0';
  for (int i = 1; i < n; i++) b[i + 1] = b[i] + (s[i] - '0');
  if (a) {
    for (int j = 0; j < n; j++)
      for (int k = j + 1; k < n + 1; k++)
        if (b[k] - b[j])
          if (a % (b[k] - b[j]) == 0) {
            ok[b[k] - b[j]]++;
          }
    for (int i = 1; i * i <= a; i++)
      if (ok[i] && a / i <= b[n]) {
        long long p = ok[a / i];
        if (i * i != a)
          l += 2ll * p * ok[i];
        else
          l += p * ok[i];
      }
  }
  if (!a) {
    for (int j = 0; j < n; j++)
      for (int k = j + 1; k < n + 1; k++)
        if (b[k] - b[j] == 0) {
          ok[0]++;
        }
    long long p = 0ll;
    for (int j = 0; j < n; j++)
      for (int k = j + 1; k < n + 1; k++)
        if (b[k] - b[j]) p++;
    l += 2ll * p * ok[0] + ok[0] * ok[0];
  }
  cout << l;
  return 0;
}
