#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000");
using namespace std;
int main() {
  long long t;
  cin >> t;
  string s;
  cin >> s;
  int n = s.length();
  long long a[500000];
  for (int i = 0; i < 500000; i++) a[i] = 0;
  for (int i = 0; i < n; i++) {
    int sum = s[i] - '0';
    a[sum]++;
    for (int j = i + 1; j < n; j++) {
      sum += s[j] - '0';
      a[sum]++;
    }
  }
  if (t == 0) {
    long long ans = 0;
    for (int i = 1; i < 500000; i++) ans += a[i] * a[0] * 2;
    ans += a[0] * (a[0]);
    cout << ans;
    return 0;
  }
  long long ans = 0;
  for (int i = 1; i < 500000; i++)
    if (t % i == 0 && t / i < 500000)
      if (t / i == i)
        ans += a[i] * a[i];
      else
        ans += a[i] * a[t / i];
  cout << ans;
  return 0;
}
