#include <bits/stdc++.h>
using namespace std;
const int N = 4005;
int matrix[N][N], s[N], a, n;
char str[N];
map<int, int> mymap;
int main() {
  scanf("%d%s", &a, str);
  n = strlen(str);
  for (int i = 0; i < n; i++) s[i] = str[i] - '0';
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) matrix[i][j] = s[i] * s[j];
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = i; j < n; j++) {
      sum += s[j];
      mymap[sum]++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = i; j < n; j++) {
      sum += s[j];
      if (sum == 0) {
        if (a == 0) ans += n * (n - 1) / 2 + n;
      } else if (a % sum == 0) {
        ans += mymap[a / sum];
      }
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
