#include <bits/stdc++.h>
using namespace std;
long long int counts[10000000];
long long int arr[4002][4002];
int main() {
  int a, b, c, i, j, k, n, m, t;
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int sum = 0;
  cin >> sum;
  string str;
  long long int temp = 0;
  cin >> str;
  for (i = 0; i < str.length(); i++) temp += str[i] - '0';
  for (i = 1; i <= str.length(); i++) {
    for (j = i; j <= str.length(); j++) {
      if (j != i)
        arr[i][j] = arr[i][j - 1] + str[j - 1] - '0';
      else
        arr[i][j] = str[j - 1] - '0';
      counts[arr[i][j]]++;
    }
  }
  long long int finans = 0;
  if (sum != 0) {
    for (i = 1; i <= str.length(); i++) {
      for (j = i; j <= str.length(); j++) {
        if (arr[i][j] != 0 && sum % arr[i][j] == 0 && sum / arr[i][j] <= temp) {
          finans += counts[sum / arr[i][j]];
        }
      }
    }
  }
  if (sum == 0) {
    n = str.length();
    long long int tot = n * (n + 1) / 2;
    finans = counts[0] * tot * 2 - counts[0] * counts[0];
  }
  cout << finans << endl;
  return 0;
}
