#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926536;
long long a[4005], c[5000005];
int main() {
  long long n, ans = 0;
  string s;
  cin >> n >> s;
  for (int i = 1; i <= s.size(); i++) a[i] = (s[i - 1] - '0') + a[i - 1];
  for (int i = 1; i <= s.size(); i++)
    for (int j = i; j <= s.size(); j++) {
      int x = a[j] - a[i - 1];
      c[x]++;
    }
  if (!n)
    ans = c[0] * (s.size() * (s.size() + 1) - c[0]);
  else {
    for (int i = 1; i <= a[s.size()]; i++)
      if (n % i == 0)
        if (n / i <= a[s.size()]) ans += c[i] * c[n / i];
  }
  cout << ans << "\n";
  return 0;
}
