#include <bits/stdc++.h>
using namespace std;
const int maxn = 5001;
char s[maxn];
long long a, p[maxn], ans, n, ansa;
map<long long, long long> cnt;
int main() {
  cin >> a;
  scanf("%s", s);
  n = strlen(s);
  for (long long i = 1; i <= n; i++) p[i] = p[i - 1] + s[i - 1] - '0';
  for (long long i = 1; i <= n; i++)
    for (long long j = i; j <= n; j++) cnt[p[j] - p[i - 1]]++;
  for (long long i = 1; i <= n; i++)
    for (long long j = i; j <= n; j++) {
      if (p[j] - p[i - 1] == 0) {
        ansa += (!a ? n * (n + 1) / 2 : 0);
        continue;
      }
      if (p[j] - p[i - 1] == sqrt(a) && (long long)sqrt(a) == sqrt(a + 0.0)) {
        ansa += cnt[(long long)sqrt(a)];
        continue;
      }
      if (a % (p[j] - p[i - 1]) == 0) ans += cnt[a / (p[j] - p[i - 1])];
    }
  cout << ans + ansa;
  return 0;
}
