#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, i, j, ans = 0, n, arr[4100], find[50000] = {}, sum = 0;
  string s;
  cin >> a >> s;
  n = s.size();
  for (i = 0; i < n; i++) arr[i] = s[i] - '0';
  for (i = 0; i < n; i++) {
    sum = 0;
    for (j = i; j < n; j++) {
      sum += arr[j];
      find[sum]++;
    }
  }
  if (a == 0)
    ans = n * (n + 1) * find[0] - find[0] * find[0];
  else {
    for (i = 0; i < n; i++) {
      sum = 0;
      for (j = i; j < n; j++) {
        sum += arr[j];
        if (sum != 0 && a % sum == 0 && a / sum <= n * 9) ans += find[a / sum];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
