#include <bits/stdc++.h>
using namespace std;
const int maxN = 4000 + 5;
const int maxW = 40 * 1000 + 5;
int cnt[maxW];
int main() {
  ios_base::sync_with_stdio(false);
  int a;
  string s;
  cin >> a >> s;
  int n = s.size();
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = i; j < n; j++) {
      tmp += s[j] - '0';
      cnt[tmp]++;
      sum++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = i; j < n; j++) {
      tmp += s[j] - '0';
      if (tmp == 0 && a == 0) ans += sum;
      if (tmp != 0 && a % tmp == 0 && a / tmp < maxW) ans += cnt[a / tmp];
    }
  }
  cout << ans << endl;
  return 0;
}
