#include <bits/stdc++.h>
using namespace std;
char str[4005];
long long a, n, repSum[40005], accuSum[4005];
int main() {
  scanf("%lld%s", &a, str);
  n = (long long)strlen(str);
  for (long long(i) = (1); i <= (long long)(n); (i)++)
    accuSum[i] = (str[i - 1] - '0') + accuSum[i - 1];
  for (long long(l) = (1); l <= (long long)(n); (l)++)
    for (long long(i) = (1); i <= (long long)(n - l + 1); (i)++)
      ++repSum[accuSum[i + l - 1] - accuSum[i - 1]];
  long long ans = 0;
  if (!a) {
    ans = repSum[0] * (n * (n + 1) - repSum[0]);
  } else {
    for (long long(i) = (1); i <= (long long)(40000); (i)++)
      if (a % i == 0 && a / i < 40000) ans += repSum[i] * repSum[a / i];
  }
  printf("%lld\n", ans);
  return 0;
}
