#include <bits/stdc++.h>
using namespace std;
const int N = 4005;
long long a;
char s[N];
map<long long, long long> cnt;
int main() {
  scanf("%lld", &a);
  scanf("%s", s);
  int len = strlen(s);
  cnt.clear();
  long long dp[N];
  dp[0] = s[0] - '0';
  for (int i = 1; i < len; i++) dp[i] = dp[i - 1] + (s[i] - '0');
  for (int i = 0; i < len; i++) dp[i] = s[i] - '0';
  for (int i = 1; i < len; i++) dp[i] += dp[i - 1];
  for (int i = 0; i < len; i++)
    for (int j = i; j < len; j++) {
      long long sum = dp[j];
      if (i != 0) sum -= dp[i - 1];
      cnt[sum]++;
    }
  if (a == 0) {
    long long ans = 0;
    for (auto data : cnt) {
      ans += 2 * cnt[0] * data.second;
    }
    ans -= cnt[0] * cnt[0];
    printf("%lld\n", ans);
    return 0;
  }
  bool kuadrat = 0;
  long long ans = 0;
  for (long long i = 1; i * i <= a; i++) {
    if (i * i == a && cnt[i] > 0) {
      kuadrat = 1;
      ans += cnt[i] * cnt[i];
    } else if (a % i == 0 && cnt[i] > 0 && cnt[a / i] > 0)
      ans += 2 * cnt[i] * cnt[a / i];
  }
  printf("%lld\n", ans);
  return 0;
}
