#include <bits/stdc++.h>
using namespace std;
inline long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
inline long long int fast_pow(long long int a, long long int b) {
  long long int res = 1;
  a %= 1000000007;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
inline bool isPrime(long long int a) {
  for (long long int i = 2; i * i <= a; i++)
    if (a % i == 0) return 0;
  return 1;
}
const int N = 4000;
int a, arr[9 * 4000 + 1];
string s;
long long int ans;
int main() {
  cin >> a >> s;
  for (int i = 0; i < s.size(); i++) {
    int sum = 0;
    for (int j = i; j < s.size(); j++) {
      sum += s[j] - '0';
      arr[sum]++;
    }
  }
  if (a == 0) {
    ans = 1LL * arr[0] * s.size() * (s.size() + 1) - 1LL * arr[0] * arr[0];
    cout << ans << '\n';
    return 0;
  }
  for (int i = 1; i * i <= a; i++) {
    if (a % i == 0 && a / i <= 9 * s.size() && arr[i] && arr[a / i]) {
      ans += 1LL * arr[i] * arr[a / i];
      if (i * i != a) ans += 1LL * arr[i] * arr[a / i];
    }
  }
  cout << ans << '\n';
  return 0;
}
