#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k;
  cin >> k;
  string s;
  cin >> s;
  vector<long long> A;
  vector<long long> prefix(s.size() + 1, 0);
  for (int i = 0; i < s.size(); i++) {
    A.push_back(s[i] - '0');
  }
  for (int i = 0; i < A.size(); i++) {
    prefix[i + 1] = prefix[i] + A[i];
  }
  vector<long long> used(1000000, 0);
  for (int i = 0; i < A.size(); i++) {
    for (int j = i; j < A.size(); j++) {
      long long sum = prefix[j + 1] - prefix[i];
      used[sum]++;
    }
  }
  long long answer = 0;
  if (k == 0) answer += used[0] * used[0];
  for (int i = 1; i < used.size(); i++) {
    if (k == 0) {
      answer += used[i] * used[0];
      answer += used[i] * used[0];
    } else {
      if (used[i] != 0 && k % i == 0 && ((k / i) < used.size())) {
        answer += used[i] * used[k / i];
      }
    }
  }
  cout << answer << endl;
  return 0;
}
