#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) a[i] = s[i - 1] - '0' + a[i - 1];
  unordered_map<int, long long> mp;
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j) ++mp[a[j] - a[i - 1]];
  long long r{};
  for (auto& o : mp) {
    if (x == 0)
      r += o.second;
    else if (o.first != 0 && x % o.first == 0)
      r += o.second * mp[x / o.first];
  }
  cout << (x ? r : (mp[0] * r << 1) - mp[0] * mp[0]);
}
