#include <bits/stdc++.h>
using namespace std;
const int N = 4100, INF = 1000000000, MOD = 1000000007, ALP = 300;
const double PI = acos(-1.0), EPS = 1e-7;
long long n;
long long sum[N];
map<long long, long long> m;
string s;
int main() {
  long long a;
  cin >> a;
  long long t;
  cin >> s;
  n = s.length();
  for (int i = 1; i <= n; i++) {
    t = 1LL * (s[i - 1] - '0');
    sum[i] = sum[i - 1] + t;
  }
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) m[sum[j] - sum[i - 1]]++;
  if (a == 0) {
    cout << 2LL * m[0] * n * (n + 1) / 2 - 1LL * m[0] * m[0] << endl;
    return 0;
  }
  if (a == 1) {
    cout << 1LL * m[1] * m[1] << endl;
    return 0;
  }
  long long res = 2LL * m[a] * m[1];
  for (long long i = 2LL; 1LL * i * i <= a; i++)
    if (a % i == 0) {
      if (1LL * i * i != a)
        res += 2LL * m[a / i] * m[i];
      else
        res += 1LL * m[i] * m[i];
    }
  cout << res << endl;
  return 0;
}
