#include <bits/stdc++.h>
using namespace std;
const int maxn = 401000;
char num[maxn];
long long cnt[maxn], a;
int main() {
  cin >> a >> num;
  long long len = strlen(num);
  int zero = 0, non_zero = 0;
  for (int i = 0; i < len; i++) {
    long long cot = 0;
    for (int j = i; j < len; j++) {
      cot += num[j] - '0';
      cnt[cot]++;
      if (cot == 0)
        zero++;
      else
        non_zero++;
    }
  }
  if (a == 0) {
    cout << (long long)(zero + non_zero) * (zero + non_zero) -
                (long long)non_zero * non_zero
         << endl;
  } else {
    long long ans = 0;
    for (int i = 1; i < maxn && i <= a; i++) {
      if (!cnt[i]) continue;
      if (a % i == 0 && a / i < maxn) ans += (long long)cnt[i] * cnt[a / i];
    }
    cout << ans << endl;
  }
  return 0;
}
