#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int a;
  cin >> a;
  string s;
  cin >> s;
  map<int, int> Freq;
  for (int i = 0; i < s.size(); i++) {
    int sum = 0;
    bool zero = false;
    for (int j = i; j < s.size(); j++) {
      sum += (s[j] - '0');
      Freq[sum]++;
    }
  }
  long long ans = 0;
  if (a == 0) {
    for (int i = 0; i < s.size(); i++) {
      int sum = 0;
      for (int j = i; j < s.size(); j++) {
        sum += s[j] - '0';
        if (sum == 0)
          ans += (s.size() * (s.size() + 1)) / 2;
        else
          ans += Freq[0];
      }
    }
    cout << ans;
    return 0;
  }
  for (auto &x : Freq) {
    if (x.first && a % x.first == 0)
      ans += (long long)Freq[a / x.first] * x.second;
  }
  cout << ans;
  return 0;
}
