#include <bits/stdc++.h>
using namespace std;
string a;
long long k, ans, n;
map<long long, long long> mp;
int main() {
  cin >> k >> a;
  n = a.size();
  for (long long i = 0; i < n; i++) {
    long long sum = 0;
    for (long long j = i; j < n; j++) sum += a[j] - '0', mp[sum]++;
  }
  for (long long i = 0; i < n; i++) {
    long long sum = 0;
    for (long long j = i; j < n; j++) {
      sum += a[j] - '0';
      if (!k && !sum)
        ans += (n + 1) * n / 2;
      else if (sum && k % sum == 0)
        ans += mp[k / sum];
    }
  }
  cout << ans << endl;
}
