#include <bits/stdc++.h>
using namespace std;
const int N = 4002;
int n = 0, a;
char ch[N];
long long ans = 0, sum[N][N], all;
long long d[N * 9];
int val(int ind) { return ch[ind - 1] - '0'; }
int main() {
  cin >> a;
  while (cin >> ch[n]) n++;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      sum[i][j] = val(j) + sum[1][j - 1] - sum[1][i - 1];
      d[sum[i][j]]++;
    }
  }
  for (int tt = 0; tt <= 4000 * 9; ++tt) all += d[tt];
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      if (sum[i][j] == 0) {
        if (a == 0) ans += all;
        continue;
      }
      int cur = a / sum[i][j];
      if (cur * sum[i][j] == a) {
        if (cur >= 0 && cur <= 4000 * 9) ans += d[cur];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
