#include <bits/stdc++.h>
using namespace std;
long long s1[4001];
long long t1[50000];
int main() {
  long long a;
  cin >> a;
  string s;
  cin >> s;
  int len = s.length();
  long long i, j;
  for (i = 0; i < len; i++) {
    s1[i + 1] = s1[i] + s[i] - '0';
  }
  for (i = 1; i <= len; i++) {
    for (j = 0; j < i; j++) {
      t1[s1[i] - s1[j]]++;
    }
  }
  long long ans = 0;
  if (a == 0) {
    for (i = 0; i <= s1[len]; i++) ans += t1[0] * t1[i];
  }
  for (i = 1; i <= s1[len]; i++)
    if ((a % i == 0) && (a / i <= s1[len])) ans += t1[i] * t1[a / i];
  cout << ans << endl;
  return 0;
}
