#include <bits/stdc++.h>
using namespace std;
const int up = 36000;
char s[4005];
long long sum[4005], cnt[up + 5];
int main() {
  int a, cc = -1;
  cc = 2;
  scanf("%d", &a);
  scanf("%s", s);
  long long res = 0;
  long long n = strlen(s);
  for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + s[i] - '0';
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) cnt[sum[j] - sum[i - 1]]++;
  if (a == 0) {
    res = 2 * cnt[0] * (n + 1) * n / 2 - cnt[0] * cnt[0];
  } else {
    for (int i = 1; i <= up; i++)
      if (a % i == 0 && a / i <= up) res += cnt[i] * cnt[a / i];
  }
  cout << res << endl;
  return 0;
}
