#include <bits/stdc++.h>
using namespace std;
long long int prefix[30000];
int main() {
  string str;
  long long int a;
  cin >> a;
  cin >> str;
  long long int n = str.length();
  map<long long int, long long int> mp;
  prefix[0] = 0;
  for (long long int i = 1; i <= n; i++)
    prefix[i] = prefix[i - 1] + str.at(i - 1) - '0';
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = i; j <= n; j++) mp[prefix[j] - prefix[i - 1]]++;
  }
  long long int sumx;
  long long int counter = 0;
  for (long long int i = 1; i * i <= a; i++) {
    if (i * i == a) {
      counter += mp[i] * mp[i];
      continue;
    }
    if (a % i == 0) {
      counter += 2 * mp[i] * mp[a / i];
    }
  }
  if (a == 0) {
    cout << n * (n + 1) * mp[0] - mp[0] * mp[0];
    return 0;
  }
  cout << counter << endl;
}
