#include <bits/stdc++.h>
using namespace std;
long long int modularExponentiation(long long int x, long long int n) {
  int result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % 1000000007;
    x = (x * x) % 1000000007;
    n = n / 2;
  }
  return result;
}
void solve() {
  long long int n, k;
  cin >> k;
  string s;
  cin >> s;
  n = s.size();
  long long int a[n];
  for (long long int i = 0; i < n; i++) a[i] = s[i] - '0';
  map<long long int, long long int> y;
  for (long long int i = 1; i <= n; i++) {
    long long int sum = 0;
    for (long long int j = 0; j < i; j++) sum += a[j];
    y[sum]++;
    for (long long int j = i; j < n; j++) {
      sum += (a[j] - a[j - i]);
      y[sum]++;
    }
  }
  long long int ans = 0;
  if (!k) ans += y[0] * ((n * (n + 1)) - y[0]);
  for (long long int i = 1; i * i <= k; i++) {
    if (k % i == 0) {
      if (y.find(i) != y.end()) {
        if (i != k / i)
          ans += (y[i] * y[k / i] * 2);
        else {
          ans += y[i] * y[k / i];
        }
      }
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
}
