#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long a, ans = 0;
  string s;
  cin >> a >> s;
  map<int, long long> mp;
  for (int i = 0; i < s.size(); i++) {
    long long sum = 0;
    for (int j = i; j < s.size(); j++) {
      sum += (s[j] - '0');
      mp[sum]++;
    }
  }
  for (auto i : mp) {
    if (i.first && a % i.first == 0) ans += i.second * mp[a / (i.first)];
    if (i.first > 35000) break;
  }
  if (!a) {
    ans *= 2;
    ans += mp[0] * mp[0];
  }
  cout << ans << endl;
  return 0;
}
