#include <bits/stdc++.h>
using namespace std;
const long long N = 4007;
const long long C = N * 10;
long long cnt[C];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long w;
  cin >> w;
  string s;
  cin >> s;
  long long n = s.size();
  long long x = 0;
  for (long long l = 0; l < n; ++l) {
    long long cur = 0;
    for (long long r = l; r < n; ++r) {
      cur += s[r] - '0';
      ++cnt[cur];
      x += cur == 0;
    }
  }
  long long ans = 0;
  for (long long l = 0; l < n; ++l) {
    long long cur = 0;
    for (long long r = l; r < n; ++r) {
      cur += s[r] - '0';
      if (w) {
        if (cur && w % cur == 0 && w / cur < C) {
          ans += cnt[w / cur];
        }
      } else {
        if (cur == 0) {
          ans += n * (n + 1) / 2;
        } else {
          ans += x;
        }
      }
    }
  }
  cout << ans << '\n';
}
