#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int a = 0;
  cin >> a;
  string s;
  cin >> s;
  vector<int> sum(1);
  for (char c : s) sum.push_back(sum.back() + c - '0');
  vector<int> cnt(sum.back() + 1);
  for (int i = 0; i < sum.size(); ++i)
    for (int j = i + 1; j < sum.size(); ++j) ++cnt[sum[j] - sum[i]];
  long long ans = 0;
  for (int i = 0; i < cnt.size(); ++i)
    for (int j = 0; j < cnt.size(); ++j)
      if (i * j == a) ans += cnt[i] * 1LL * cnt[j];
  cout << ans << endl;
  return 0;
}
