#include <bits/stdc++.h>
using namespace std;
long long this_sum[100000], wait_sum[100000];
int main() {
  int a;
  cin >> a;
  string s;
  cin >> s;
  int len = s.size();
  for (int i = 0; i < len; i++) {
    int sum = 0;
    for (int j = i; j < len; j++) {
      sum += s[j] - '0';
      if (sum == 0) {
        this_sum[sum]++;
      } else if (a % sum == 0) {
        if (sum <= a / sum) this_sum[sum]++;
        if (sum >= a / sum) wait_sum[a / sum]++;
      }
    }
  }
  if (a == 0) {
    cout << this_sum[0] * (len * (len + 1) - this_sum[0]) << endl;
  } else {
    long long sum = 0;
    int limit = (int)sqrt(a + 0.5);
    for (int i = 1; i <= limit; i++)
      sum += this_sum[i] * wait_sum[i] * (1 + (i * i != a));
    cout << sum << endl;
  }
  return 0;
}
