#include <bits/stdc++.h>
using namespace std;
map<long long, long long> my;
int main() {
  int n, r1 = 0;
  cin >> n;
  string s;
  cin >> s;
  int l = s.length();
  for (int i = 0; i < l; i++) {
    for (int j = i; j < l; j++) {
      r1 += s[j] - '0';
      my[r1]++;
    }
    r1 = 0;
  }
  if (n == 0) {
    cout << 2 * (my[0] * (l * (l + 1) / 2)) - my[0] * my[0] << endl;
    return 0;
  }
  long long res = 0;
  for (map<long long, long long>::iterator it = my.begin(); it != my.end();
       it++) {
    if ((it->first) && n % (it->first) == 0)
      res += my[it->first] * my[n / (it->first)];
  }
  cout << res;
  return 0;
}
