#include <bits/stdc++.h>
using namespace std;
bool rev(long long x, long long y) { return x > y; }
void input_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cin >> a[i];
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return a.second < b.second;
}
bool sortinrev(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.first > b.first);
}
void print_vec(vector<long long> &v) {
  for (auto i : v) cout << i << " ";
  cout << '\n';
}
bool sortinrevbysec(const pair<long long, long long> &a,
                    const pair<long long, long long> &b) {
  return (a.second > b.second);
}
void print_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cout << a[i] << " ";
  cout << '\n';
}
template <typename... T>
void input(T &...args) {
  ((cin >> args), ...);
}
template <typename... T>
void print(T &&...args) {
  ((cout << args << '\n'), ...);
}
template <typename... T>
void deb(T &&...args) {
  cout << "~~ ";
  ((cout << args << " "), ...);
  cout << '\n';
}
void stand8th() {
  long long summ;
  input(summ);
  string s;
  input(s);
  long long n = (long long)(s.size());
  long long a[n];
  for (long long i = 0; i < n; i += 1) {
    a[i] = (long long)(s[i] - '0');
  }
  for (long long i = 1; i < n; i += 1) a[i] += a[i - 1];
  map<long long, long long> mpp;
  for (long long i = 0; i < n; i += 1) {
    mpp[a[i]]++;
    for (long long j = i + 1; j < n; j += 1) {
      mpp[a[j] - a[i]]++;
    }
  }
  long long ans = 0;
  for (auto vbn : mpp) {
    if (vbn.first != 0 && summ % vbn.first == 0) {
      ans += vbn.second * mpp[summ / vbn.first];
    } else if (vbn.first == 0 && summ == 0) {
      ans += vbn.second * (n * (n + 1) / 2);
    }
  }
  print(ans);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tin = 1;
  while (tin--) {
    stand8th();
  }
  return 0;
}
