#include <bits/stdc++.h>
using namespace std;
const int N = 100009;
const long long MOD = 1e9 + 7;
int dX[] = {0, 0, 1, -1};
int dY[] = {1, -1, 0, 0};
long long GCD(long long num, long long ones) {
  return !ones ? num : GCD(ones, num % ones);
}
string s;
map<int, int> mp;
long long ans, sum;
int arr[4040];
int main() {
  scanf("%lld", &sum);
  cin >> s;
  int n = (s.size());
  for (int i = 0; i < n; ++i) arr[i + 1] = s[i] - '0', arr[i + 1] += arr[i];
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      mp[arr[j] - arr[i]]++;
    }
  }
  if (sum == 0) {
    if (mp.count(0))
      cout << mp[0] * (n * 1LL * n - mp[0] + n);
    else
      puts("0");
    return 0;
  }
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
    if (!it->first) continue;
    if (sum % it->first == 0 && mp.count(sum / it->first))
      ans += mp[sum / it->first] * 1LL * it->second;
  }
  cout << ans;
  return 0;
}
