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