#include <bits/stdc++.h>
using namespace std;
long long n, a, sum[4005], ans;
char str[4005];
map<long long, long long> mp;
int main() {
  while (~scanf("%lld", &a)) {
    scanf("%s", str + 1);
    n = strlen(str + 1);
    for (long long i = 1; i <= n; i++) {
      sum[i] = sum[i - 1] + str[i] - '0';
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= i; j++) {
        long long now = sum[i] - sum[j - 1];
        mp[now]++;
      }
    }
    for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();
         it++) {
      long long now = it->first;
      if (!now) {
        if (!a) {
          ans += it->second * n * (n + 1) / 2;
        }
        continue;
      }
      if (a % now) {
        continue;
      }
      if (!mp.count(a / now)) {
        continue;
      }
      ans += it->second * mp[a / now];
    }
    printf("%lld\n", ans);
  }
}
