#include <bits/stdc++.h>
using namespace std;
const int MAX = 10000 + 10;
int a, n;
char s[MAX];
long long sum[MAX];
vector<long long> p;
int main() {
  int i, j, j2;
  scanf("%d", &a);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for ((i) = (1); (i) <= (n); ++(i)) sum[i] = sum[i - 1] + s[i] - '0';
  for ((i) = (1); (i) <= (n); ++(i))
    for ((j) = (i); (j) <= (n); ++(j)) p.push_back(sum[j] - sum[i - 1]);
  sort(p.begin(), p.end());
  j = p.size() - 1;
  j2 = p.size() - 1;
  long long ans = 0;
  for (i = 0; i < (int)p.size(); ++i) {
    for (; j >= 0 && (long long)p[j] * p[i] > a; --j)
      ;
    for (; j2 >= 0 && (long long)p[j2] * p[i] >= a; --j2)
      ;
    ans += j - j2;
  }
  cout << ans << endl;
  return 0;
}
