#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T &maxx(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int &madd(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
int &msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000007;
  return a;
}
int &mmult(int &a, int b) { return a = (long long)a * b % 1000000007; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
int n, m, q;
char S[4012];
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(q)) > 0;
       ++ts) {
    scanf(
        "%"
        "s",
        &(S));
    n = strlen(S);
    map<int, int> D;
    m = 0;
    for (i = (0); i < (n); ++i) {
      int s = 0;
      for (j = (i); j < (n); ++j) {
        s += S[j] - '0';
        ++m;
        ++D[s];
      }
    }
    long long res = 0;
    for (i = (0); i < (n); ++i) {
      int s = 0;
      for (j = (i); j < (n); ++j) {
        s += S[j] - '0';
        if (s == 0) {
          if (q == 0) res += m;
        } else if (q % s == 0) {
          res += D[q / s];
        }
      }
    }
    printf(
        "%"
        "I64d",
        (res));
    printf("\n"), firstout = 1;
  }
  return 0;
}
