#include <bits/stdc++.h>
using namespace std;
int a;
char st[4444];
int sum[4444];
map<int, int> p;
long long ans = 0;
int len, tot;
int main() {
  cin >> a;
  scanf("%s", st);
  for (int i = 0, j = strlen(st); i < j; i++) {
    sum[i + 1] = sum[i] + st[i] - '0';
  }
  for (int i = 1, len = strlen(st); i <= len; i++)
    for (int j = 1; j <= i; j++) {
      p[sum[i] - sum[j - 1]]++;
      tot++;
    }
  if (a == 0) {
    ans = 1ll * p[0] * p[0];
    ans += 2ll * p[0] * (tot - p[0]);
  } else
    for (int i = 1, len = (int)sqrt(a + 1); i <= len; i++) {
      if (a % i != 0) continue;
      int j = a / i;
      long long tmp;
      if (i != j)
        tmp = 2ll * p[i] * p[j];
      else
        tmp = 1ll * p[i] * p[i];
      ans += tmp;
    }
  cout << ans << endl;
}
