#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
	int A;
	cin >> A;
	string B;
	cin >> B;
	for(int i=0;i<B.size();i++)
		B[i]-='0';
	map<int,int> mp,mp1;
	for(int j=1;j*j<=A;j++){
		if(A%j==0)
			mp[j]=1;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(A/it->first==it->first)
			continue;
		mp1[A/it->first]=1;
	}
	mp.insert(mp1.begin(),mp1.end());
	mp1.clear();
	map<int,pair<int,int> >mp2;
	int array[B.size()+1];
	fill(array,array+B.size()+1,0);//ilk rakam 1 son rakam bnin sizeı
	for(int i=1;i<=B.size();i++)
		array[i]=array[i-1]+B[i-1];
	for(int i=0;i<B.size();i++){
		for(int j=i+1;j<=B.size();j++){
			if(mp.find(array[j]-array[i])!=mp.end()){
				if((array[j]-array[i])<=A/(array[j]-array[i])){
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].first++;
				}
				else{
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].second++;
				}
			}
		}
	}
	map<int,pair<int,int> >::iterator it;
	int sum=0;
	for(it=mp2.begin();it!=mp2.end();it++){
		//cout << it->first << " " << it->second.first << " " << it->second.second << endl;
		if(it->first*it->first==A){
			sum+=it->second.first*it->second.first;
		}
		else{
			sum+=it->second.first*it->second.second*2;
		}
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
	int A;
	cin >> A;
	string B;
	cin >> B;
	for(int i=0;i<B.size();i++)
		B[i]-='0';
	map<int,int> mp,mp1;
	for(int j=1;j*j<=A;j++){
		if(A%j==0)
			mp[j]=1;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		mp1[A/it->first]=1;
	}
	mp.insert(mp1.begin(),mp1.end());
	mp1.clear();
	map<int,pair<int,int> >mp2;
	int array[B.size()+1];
	fill(array,array+B.size()+1,0);//ilk rakam 1 son rakam bnin sizeı
	for(int i=1;i<=B.size();i++)
		array[i]=array[i-1]+B[i-1];
	for(int i=0;i<B.size();i++){
		for(int j=i+1;j<=B.size();j++){
			if(mp.find(array[j]-array[i])!=mp.end()){
				if((array[j]-array[i])<=A/(array[j]-array[i])){
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].first++;
				}
				else{
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].second++;
				}
			}
		}
	}
	map<int,pair<int,int> >::iterator it;
	int sum=0;
	for(it=mp2.begin();it!=mp2.end();it++){
		//cout << it->first << " " << it->second.first << " " << it->second.second << endl;
		if(it->first*it->first==A){
			sum+=it->second.first*it->second.first;
		}
		else{
			sum+=it->second.first*it->second.second*2;
		}
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
	int A;
	cin >> A;
	string B;
	cin >> B;
	for(int i=0;i<B.size();i++)
		B[i]-='0';
	if(A==0){
		long long sifir=0;
		int array[B.size()+1];
		fill(array,array+B.size()+1,0);//ilk rakam 1 son rakam bnin sizeı
		for(int i=1;i<=B.size();i++)
			array[i]=array[i-1]+B[i-1];
		for(int i=0;i<B.size();i++){
			for(int j=i+1;j<=B.size();j++){
				if(array[j]-array[i]==0){
					sifir++;
				}
			}
		}
		long long result=B.size()*(B.size()+1)/2-sifir;
		result=result*sifir*2+sifir*sifir;
		cout << result << endl;
		return 0;
	}
	map<int,int> mp,mp1;
	for(int j=1;j*j<=A;j++){
		if(A%j==0)
			mp[j]=1;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(A/it->first==it->first)
			continue;
		mp1[A/it->first]=1;
	}
	mp.insert(mp1.begin(),mp1.end());
	mp1.clear();
	map<int,pair<int,int> >mp2;
	int array[B.size()+1];
	fill(array,array+B.size()+1,0);//ilk rakam 1 son rakam bnin sizeı
	for(int i=1;i<=B.size();i++)
		array[i]=array[i-1]+B[i-1];
	for(int i=0;i<B.size();i++){
		for(int j=i+1;j<=B.size();j++){
			if(mp.find(array[j]-array[i])!=mp.end()){
				//cout << array[j]-array[i] << endl;
				if((array[j]-array[i])<=A/(array[j]-array[i])){
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].first++;
				}
				else{
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].second++;
				}
			}
		}
	}
	map<int,pair<int,int> >::iterator it;
	long long sum=0;
	for(it=mp2.begin();it!=mp2.end();it++){
		//cout << it->first << " " << it->second.first << " " << it->second.second << endl;
		if(it->first*it->first==A){
			sum+=(it->second.first*(long long)(it->second.first));
		}
		else{
			sum+=it->second.first*(long long)it->second.second*2;
		}
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
	int A;
	cin >> A;
	string B;
	cin >> B;
	for(int i=0;i<B.size();i++)
		B[i]-='0';
	if(A==0){
		int sifir=0;
		int array[B.size()+1];
		fill(array,array+B.size()+1,0);//ilk rakam 1 son rakam bnin sizeı
		for(int i=1;i<=B.size();i++)
			array[i]=array[i-1]+B[i-1];
		for(int i=0;i<B.size();i++){
			for(int j=i+1;j<=B.size();j++){
				if(array[j]-array[i]==0){
					sifir++;
				}
			}
		}
		long long result=B.size()*(B.size()+1)/2-sifir;
		result=result*sifir*2+sifir*sifir;
		cout << result << endl;
		return 0;
	}
	map<int,int> mp,mp1;
	for(int j=1;j*j<=A;j++){
		if(A%j==0)
			mp[j]=1;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(A/it->first==it->first)
			continue;
		mp1[A/it->first]=1;
	}
	mp.insert(mp1.begin(),mp1.end());
	mp1.clear();
	map<int,pair<int,int> >mp2;
	int array[B.size()+1];
	fill(array,array+B.size()+1,0);//ilk rakam 1 son rakam bnin sizeı
	for(int i=1;i<=B.size();i++)
		array[i]=array[i-1]+B[i-1];
	for(int i=0;i<B.size();i++){
		for(int j=i+1;j<=B.size();j++){
			if(mp.find(array[j]-array[i])!=mp.end()){
				//cout << array[j]-array[i] << endl;
				if((array[j]-array[i])<=A/(array[j]-array[i])){
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].first++;
				}
				else{
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].second++;
				}
			}
		}
	}
	map<int,pair<int,int> >::iterator it;
	long long sum=0;
	for(it=mp2.begin();it!=mp2.end();it++){
		//cout << it->first << " " << it->second.first << " " << it->second.second << endl;
		if(it->first*it->first==A){
			sum+=(it->second.first*(it->second.first));
		}
		else{
			sum+=it->second.first*it->second.second*2;
		}
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
	int A;
	cin >> A;
	string B;
	cin >> B;
	for(int i=0;i<B.size();i++)
		B[i]-='0';
	if(A==0){
		int sifir=0;
		int array[B.size()+1];
		fill(array,array+B.size()+1,0);//ilk rakam 1 son rakam bnin sizeı
		for(int i=1;i<=B.size();i++)
			array[i]=array[i-1]+B[i-1];
		for(int i=0;i<B.size();i++){
			for(int j=i+1;j<=B.size();j++){
				if(array[j]-array[i]==0){
					sifir++;
				}
			}
		}
		int result=B.size()*(B.size()+1)/2-sifir;
		result=result*sifir*2+sifir*sifir;
		cout << result << endl;
		return 0;
	}
	map<int,int> mp,mp1;
	for(int j=1;j*j<=A;j++){
		if(A%j==0)
			mp[j]=1;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(A/it->first==it->first)
			continue;
		mp1[A/it->first]=1;
	}
	mp.insert(mp1.begin(),mp1.end());
	mp1.clear();
	map<int,pair<int,int> >mp2;
	int array[B.size()+1];
	fill(array,array+B.size()+1,0);//ilk rakam 1 son rakam bnin sizeı
	for(int i=1;i<=B.size();i++)
		array[i]=array[i-1]+B[i-1];
	for(int i=0;i<B.size();i++){
		for(int j=i+1;j<=B.size();j++){
			if(mp.find(array[j]-array[i])!=mp.end()){
				//cout << array[j]-array[i] << endl;
				if((array[j]-array[i])<=A/(array[j]-array[i])){
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].first++;
				}
				else{
					mp2[min(A/(array[j]-array[i]),(array[j]-array[i]))].second++;
				}
			}
		}
	}
	map<int,pair<int,int> >::iterator it;
	int sum=0;
	for(it=mp2.begin();it!=mp2.end();it++){
		//cout << it->first << " " << it->second.first << " " << it->second.second << endl;
		if(it->first*it->first==A){
			sum+=(it->second.first*(it->second.first));
		}
		else{
			sum+=it->second.first*it->second.second*2;
		}
	}
	cout << sum << endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	if(n==0)
	{
		int yy=0;
		for(i=0;a[i]!='\0';i++)
			if(a[i]=='0')
				yy++;
		int ans=yy*i+yy*(i-yy);
		cout<<ans<<endl;
		return 0;
	}
	long long pre[15000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
//	cout<<pre[length-1]<<endl;
	int hash[1000000]={0};
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
		//	else if(hash[pre[j]-pre[i]]==0)
		//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			//cout<<sum<<" " <<n<<" "<<hash[n/sum]<<endl;
			if(sum!=0 &&n%sum==0)
			{
				int k=n/sum;
//				cout<<sum <<" "<<i <<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0)
					ans+=hash[k];
		//		if(j-i>1)
		//			ans+=hash[k];
			}
			else if(sum==0 && n==0)
				ans++;
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if(sum!=0&&n%sum==0)
		{
			int k=n/sum;
//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0)
				ans+=hash[k];
		}
		else if(sum==0 && n==0)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
long long	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	if(n==0)
	{
		long long int yy=0;
		for(i=0;a[i]!='\0';i++)
			if(a[i]=='0')
				yy++;
		long long int ans=yy*i+yy*(i-yy);
		cout<<ans<<endl;
		return 0;
	}
	long long pre[15000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
//	cout<<pre[length-1]<<endl;
//	int hash[1000000]={0};
	map <long long,long long int> hash;
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
		//	else if(hash[pre[j]-pre[i]]==0)
		//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	long long int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			if(sum!=0&&n%sum==0)
			{
				int k=n/sum;
//				cout<<sum<<" "<<i<<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0)
					ans+=hash[k];

			}
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if( sum!=0&&n%sum==0)
		{
			int k=n/sum;
//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0)
				ans+=hash[k];
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	if(n==0)
	{
		int yy=0;
		for(i=0;a[i]!='\0';i++)
			if(a[i]=='0')
				yy++;
		int ans=yy*i+yy*(i-yy);
		cout<<ans<<endl;
		return 0;
	}
	long long pre[150000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
//	cout<<pre[length-1]<<endl;
//	int hash[1000000]={0};
	map <long long,int> hash;
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
		//	else if(hash[pre[j]-pre[i]]==0)
		//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			//cout<<sum<<" " <<n<<" "<<hash[n/sum]<<endl;
			if(sum!=0 &&n%sum==0)
			{
				int k=n/sum;
//				cout<<sum <<" "<<i <<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0)
					ans+=hash[k];
		//		if(j-i>1)
		//			ans+=hash[k];
			}
			else if(sum==0 && n==0)
				ans++;
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if(sum!=0&&n%sum==0)
		{
			int k=n/sum;
//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0)
				ans+=hash[k];
		}
		else if(sum==0 && n==0)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	if(n==0)
	{
		int yy=0;
		for(i=0;a[i]!='\0';i++)
			if(a[i]=='0')
				yy++;
		int ans=yy*i+yy*(i-yy);
		cout<<ans<<endl;
		return 0;
	}
	long long pre[150000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
//	cout<<pre[length-1]<<endl;
	int hash[1000000]={0};
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
		//	else if(hash[pre[j]-pre[i]]==0)
		//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			//cout<<sum<<" " <<n<<" "<<hash[n/sum]<<endl;
			if(sum!=0 &&n%sum==0)
			{
				int k=n/sum;
//				cout<<sum <<" "<<i <<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0 && k<1000000 && k>=0)
					ans+=hash[k];
		//		if(j-i>1)
		//			ans+=hash[k];
			}
			else if(sum==0 && n==0)
				ans++;
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if(sum!=0&&n%sum==0)
		{
			int k=n/sum;
//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0 && k<1000000 && k>=0)
				ans+=hash[k];
		}
		else if(sum==0 && n==0)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(n>4000*9+10)
	{
		cout<<0<<endl;
		return 0;
	}
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	if(n==0)
	{
		int yy=0;
		for(i=0;a[i]!='\0';i++)
			if(a[i]=='0')
				yy++;
		int ans=yy*i+yy*(i-yy);
		cout<<ans<<endl;
		return 0;
	}
	long long pre[150000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
//	cout<<pre[length-1]<<endl;
	int hash[1000000]={0};
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
		//	else if(hash[pre[j]-pre[i]]==0)
		//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			//cout<<sum<<" " <<n<<" "<<hash[n/sum]<<endl;
			if(sum!=0 &&n%sum==0)
			{
				int k=n/sum;
//				cout<<sum <<" "<<i <<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0 && k<1000000 && k>=0)
					ans+=hash[k];
		//		if(j-i>1)
		//			ans+=hash[k];
			}
			else if(sum==0 && n==0)
				ans++;
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if(sum!=0&&n%sum==0)
		{
			int k=n/sum;
//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0 && k<1000000 && k>=0)
				ans+=hash[k];
		}
		else if(sum==0 && n==0)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
	long long	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	if(n==0)
	{
		long long int yy=0;
		for(i=0;a[i]!='\0';i++)
			if(a[i]=='0')
				yy++;
		cout<<yy<<endl;
		long long int ans=yy*i+yy*(i-yy);
		cout<<ans<<endl;
		return 0;
	}
	long long pre[15000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
	//	cout<<pre[length-1]<<endl;
	//	int hash[1000000]={0};
	map <long long,long long int> hash;
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
			//	else if(hash[pre[j]-pre[i]]==0)
			//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	long long int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			if(sum!=0&&n%sum==0)
			{
				long long	int k=n/sum;
				//				cout<<sum<<" "<<i<<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0)
					ans+=hash[k];

			}
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if( sum!=0&&n%sum==0)
		{
			long long	int k=n/sum;
			//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0)
				ans+=hash[k];
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0;
		return 0;
	}
	long long pre[5000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
	int hash[1000000]={0};
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
		//	else if(hash[pre[j]-pre[i]]==0)
		//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			//cout<<sum<<" " <<n<<" "<<hash[n/sum]<<endl;
			if(n%sum==0)
			{
				int k=n/sum;
//				cout<<sum <<" "<<i <<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0)
					ans+=hash[k];
		//		if(j-i>1)
		//			ans+=hash[k];
			}
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if(n%sum==0)
		{
			int k=n/sum;
//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0)
				ans+=hash[k];
		}

	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
long long	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	if(n==0)
	{
		long long int yy=0;
		for(i=0;a[i]!='\0';i++)
			if(a[i]=='0')
				yy++;
		long long int ans=yy*i+yy*(i-yy);
		cout<<ans<<endl;
		return 0;
	}
	long long pre[15000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
//	cout<<pre[length-1]<<endl;
//	int hash[1000000]={0};
	map <long long,long long int> hash;
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
		//	else if(hash[pre[j]-pre[i]]==0)
		//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	long long int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			if(sum!=0&&n%sum==0)
			{
			long long	int k=n/sum;
//				cout<<sum<<" "<<i<<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0)
					ans+=hash[k];

			}
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if( sum!=0&&n%sum==0)
		{
		long long	int k=n/sum;
//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0)
				ans+=hash[k];
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
long long	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
	if(n==0)
	{
		long long int yy=0;
		for(i=0;a[i]!='\0';i++)
			if(a[i]=='0')
				yy++;
		long long int ans=yy*i+yy*(i-yy);
		cout<<ans<<endl;
		return 0;
	}
	long long pre[150000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
//	cout<<pre[length-1]<<endl;
//	int hash[1000000]={0};
	map <long long,int> hash;
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
		//	else if(hash[pre[j]-pre[i]]==0)
		//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	long long int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			if(n%sum==0)
			{
				int k=n/sum;
//				cout<<sum<<" "<<i<<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0)
					ans+=hash[k];

			}
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if(n%sum==0)
		{
			int k=n/sum;
//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0)
				ans+=hash[k];
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
#define pii pair<int, int>
#define VI vector < int >
#define PB push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORD(i,a,b) for(i=a;i>b;i--)
typedef long long LL;
using namespace std;
int main()
{
	long long	int i,j,k,n;
	cin>>n;
	char a[1000000];
	cin>>a;
	if(a[1]=='\0')
	{
		if(n+'0'==a[0])
			cout<<1<<endl;
		else
			cout<<0<<endl;
		return 0;
	}
/*	if(n==0)
	{
		long long int yy=0;
		for(i=0;a[i]!='\0';i++)
			if(a[i]=='0')
				yy++;
		cout<<yy<<endl;
		long long int ans=yy*i+yy*(i-yy);
		cout<<ans<<endl;
		return 0;
	}*/
	long long pre[15000]={0};
	pre[0]=a[i]-'0';
	for(i=1;a[i]!='\0';i++)
	{
		pre[i]=pre[i-1]+(a[i]-'0');
	}
	int length=i;
	//	for(i=0;i<length;i++)
	//		cout<<pre[i]<<" ";
	//	cout<<endl;
	//	cout<<pre[length-1]<<endl;
	//	int hash[1000000]={0};
	map <long long,long long int> hash;
	for(i=0;i<length;i++)
	{	for(j=i+1;j<length;j++)
		{
			//if(j-i==1)
			hash[pre[j]-pre[i]]++;
			//	else if(hash[pre[j]-pre[i]]==0)
			//		hash[pre[j]-pre[i]]=1;
		}
	}
	for(i=0;i<length;i++)
		hash[pre[i]]++;
	if(n==0)
	{
		cout<<hash[0]*(length*(length+1)-hash[0])<<endl;
		return 0;
	}
	long long int ans=0;
	for(i=0;i<length;i++)
	{
		for(j=i+1;j<length;j++)
		{
			long long sum=pre[j]-pre[i];
			if(sum!=0&&n%sum==0)
			{
				long long	int k=n/sum;
				//				cout<<sum<<" "<<i<<" "<<j<<" "<<k<<" "<<hash[k]<<endl;
				if(hash[k]!=0)
					ans+=hash[k];

			}
		}
	}
	for(i=0;i<length;i++)
	{
		long long sum=pre[i];
		if( sum!=0&&n%sum==0)
		{
			long long	int k=n/sum;
			//				cout<<sum <<" "<<i<<" "<<k<<" "<<hash[k]<<endl;
			if(hash[k]!=0)
				ans+=hash[k];
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;
#define all(aa) (aa.begin(), aa.end());

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    vector<ll> div;
    for(int i = 1; i*i <= n; ++i)
    {
        if((n%i) == 0)
        {
            div.pb(i);
            if(i*i != n)
                div.pb(n/i);
        }
    }

    map<ll, ll> m;
    forn(i,0,s.size())
    {
        ll su = 0;
        forn(j,i,s.size())
        {
            su += s[j]-'0';
            m[su]++;
        }
    }

    forn(i,0,div.size())
        ans += m[div[i]] * m[n/div[i]];

    if(!n && m[0])
        ans += m[0] * (s.size()*(s.size()+1)) - 1;

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;
#define all(aa) (aa.begin(), aa.end());

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    vector<ll> div;
    for(int i = 1; i*i <= n; ++i)
    {
        if((n%i) == 0)
        {
            div.pb(i);
            if(i*i != n)
                div.pb(n/i);
        }
    }

    map<ll, ll> m;
    forn(i,0,s.size())
    {
        ll su = 0;
        forn(j,i,s.size())
        {
            su += s[j]-'0';
            m[su]++;
        }
    }

    forn(i,0,div.size())
        ans += m[div[i]] * m[n/div[i]];

    if(m[0])
        ans += m[0] * (m.size()*(m.size()+1))/2;

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;
#define all(aa) (aa.begin(), aa.end());

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    vector<ll> div;
    for(int i = 1; i*i <= n; ++i)
    {
        if((n%i) == 0)
        {
            div.pb(i);
            if(i*i != n)
                div.pb(n/i);
        }
    }

    map<ll, ll> m;
    forn(i,0,s.size())
    {
        ll su = 0;
        forn(j,i,s.size())
        {
            su += s[j]-'0';
            m[su]++;
        }
    }

    forn(i,0,div.size())
        ans += m[div[i]] * m[n/div[i]];

    if(m[0])
        ans += m[0] * (s.size()*(s.size()+1));

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;
#define all(aa) (aa.begin(), aa.end());

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    vector<int> div;
    for(int i = 1; i*i <= n; ++i)
    {
        if((n%i) == 0)
        {
            div.pb(i);
            if(i*i != n)
                div.pb(n/i);
        }
    }

    map<ll, int> m;
    forn(i,0,s.size())
    {
        ll su = 0;
        forn(j,i,s.size())
        {
            su += s[j]-'0';
            m[su]++;
        }
    }

    forn(i,0,div.size())
        ans += m[div[i]] * m[n/div[i]];

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

string s, ns;
vector<vector<int> > a;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("./input.txt", "r", stdin);
#endif

    int x, n;
    cin >> x;
    string s;
    cin >> s;
    n = s.size();
    vector<int> a(36001, 0);
    forn(i,0,n)
    {
        int c = 0;
        forn(j,i,n)
        {
            c += (s[j] - '0');
            a[c]++;
        }
    }

    set<int> div;
    for(int i = 1; i*i <= x; ++i)
    {
        if(x%i == 0)
        {
            div.insert(i);
            div.insert(x/i);
        }
    }

    ll ans = 0;
    for(set<int>::iterator d = div.begin(); d != div.end(); ++d)
    {
        if(*d <= 36000 && x/(*d) <= 36000)
            ans += a[*d] * a[x/(*d)];
    }

    if (!x)
    {
        ans = n*(n+1)*a[0] - a[0]*a[0];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;
#define all(aa) (aa.begin(), aa.end());

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    vector<ll> div;
    for(int i = 1; i*i <= n; ++i)
    {
        if((n%i) == 0)
        {
            div.pb(i);
            if(i*i != n)
                div.pb(n/i);
        }
    }

    map<ll, ll> m;
    forn(i,0,s.size())
    {
        ll su = 0;
        forn(j,i,s.size())
        {
            su += s[j]-'0';
            m[su]++;
        }
    }

    forn(i,0,div.size())
        ans += m[div[i]] * m[n/div[i]];

    if(!n && m[0])
        ans += m[0] * (s.size()*(s.size()+1));

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;
#define all(aa) (aa.begin(), aa.end());

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    vector<ll> div;
    for(int i = 1; i*i <= n; ++i)
    {
        if((n%i) == 0)
        {
            div.pb(i);
            if(i*i != n)
                div.pb(n/i);
        }
    }

    map<ll, ll> m;
    forn(i,0,s.size())
    {
        ll su = 0;
        forn(j,i,s.size())
        {
            su += s[j]-'0';
            m[su]++;
        }
    }

    forn(i,0,div.size())
        ans += m[div[i]] * m[n/div[i]];

    if(!n && m[0])
        ans += m[0] * (s.size()*(s.size()+1))/2;

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;
#define all(aa) (aa.begin(), aa.end());

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    vector<ll> div;
    for(int i = 1; i*i <= n; ++i)
    {
        if((n%i) == 0)
        {
            div.pb(i);
            if(i*i != n)
                div.pb(n/i);
        }
    }

    map<ll, ll> m;
    forn(i,0,s.size())
    {
        ll su = 0;
        forn(j,i,s.size())
        {
            su += s[j]-'0';
            m[su]++;
        }
    }

    forn(i,0,div.size())
        ans += m[div[i]] * m[n/div[i]];

    cout << ans + 2*m[0]*(ll)m.size() << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

string s, ns;
vector<vector<int> > a;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("./input.txt", "r", stdin);
#endif

    int x, n;
    cin >> x;
    string s;
    cin >> s;
    n = s.size();
    vector<int> a(100001, 0);
    forn(i,0,n)
    {
        int c = 0;
        forn(j,i,n)
        {
            c += (s[j] - '0');
            a[c]++;
        }
    }

    set<int> div;
    for(int i = 1; i*i <= x; ++i)
    {
        if(x%i == 0)
        {
            div.insert(i);
            div.insert(x/i);
        }
    }

    ll ans = 0;
    for(set<int>::iterator d = div.begin(); d != div.end(); ++d)
    {
        ans += a[*d] * a[x/(*d)];
    }

    if (!x)
    {
        ans = n*(n+1)*a[0] - a[0]*a[0];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

string s, ns;
vector<vector<int> > a;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("./input.txt", "r", stdin);
#endif

    int x, n;
    cin >> x;
    string s;
    cin >> s;
    n = s.size();
    vector<int> a(36001, 0);
    forn(i,0,n)
    {
        int c = 0;
        forn(j,i,n)
        {
            c += (s[j] - '0');
            a[c]++;
        }
    }

    set<int> div;
    for(int i = 1; i*i <= x; ++i)
    {
        if(x%i == 0)
        {
            div.insert(i);
            div.insert(x/i);
        }
    }

    ll ans = 0;
    for(set<int>::iterator d = div.begin(); d != div.end(); ++d)
    {
        ans += a[*d] * a[x/(*d)];
    }

    if (!x)
    {
        ans = n*(n+1)*a[0] - a[0]*a[0];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

string s, ns;
vector<vector<int> > a;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("./input.txt", "r", stdin);
#endif

    ll x, n;
    cin >> x;
    string s;
    cin >> s;
    n = s.size();
    vector<ll> a(36001, 0);
    forn(i,0,n)
    {
        int c = 0;
        forn(j,i,n)
        {
            c += (s[j] - '0');
            a[c]++;
        }
    }

    set<int> div;
    for(int i = 1; i*i <= x; ++i)
    {
        if(x%i == 0)
        {
            div.insert(i);
            div.insert(x/i);
        }
    }

    ll ans = 0;
    for(set<int>::iterator d = div.begin(); d != div.end(); ++d)
    {
        if(*d <= 36000 && x/(*d) <= 36000)
            ans += a[*d] * a[x/(*d)];
    }

    if (!x)
    {
        ans = n*(n+1)*a[0] - a[0]*a[0];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <queue>
#include <time.h>
#include <list>

#define forn(iii,sss,nnn) for(ll iii=sss;iii<nnn;++iii)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pl(aa) cout << aa << endl;
#define ps(aa) cout << aa << ' ';
#define show(aa) forn(iii,0,aa.size()) { ps(aa[iii]); } cout << endl;
#define all(aa) (aa.begin(), aa.end());

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MAX = 10000000000000000LL;
const ll MOD = 1e9+7;
const ld EPS = 1e-5;
const ld PI = 3.14159265358979323846;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    vector<ll> div;
    for(int i = 1; i*i <= n; ++i)
    {
        if((n%i) == 0)
        {
            div.pb(i);
            if(i*i != n)
                div.pb(n/i);
        }
    }

    map<ll, ll> m;
    forn(i,0,s.size())
    {
        ll su = 0;
        forn(j,i,s.size())
        {
            su += s[j]-'0';
            m[su]++;
        }
    }

    forn(i,0,div.size())
        ans += m[div[i]] * m[n/div[i]];

    if(m[0])
        ans += m[0] * (s.size()*(s.size()+1))/2;

    cout << ans << endl;
    return 0;
}


#include <bits/stdtr1c++.h>

using namespace std;

typedef long long ll;

int arr[2005*4005];
int sum[4005];
int main() {
    int a; cin >> a;
    string s; cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        arr[i] = s[i]-'0';
    }
    partial_sum(arr, arr+n, sum);

    int c = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (i == 0) arr[c++] = sum[j];
            else arr[c++] = sum[j]-sum[i-1];
        }
    }
    sort(arr, arr+c);

    ll ans = 0;
    for (int i = 0; i < c; i++) {
        if (a == 0 && arr[i] == 0) {
            ans += c;
        } else if (arr[i] != 0 && a%arr[i] == 0) {
            int hi = upper_bound(arr, arr+c, a/arr[i]) - arr;
            int lo = lower_bound(arr, arr+c, a/arr[i]) - arr;
            if (arr[hi-1] != a/arr[i]) continue;
            ans += hi-lo;
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

long long a[16000000];
int part[4001];

inline int fish(int key, int lo, int hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    int mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline int cd(int key, int c) {
    int pos = fish(key, 0, c);
    if (pos == -1) return 0;
    int high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline int count(long long n, int c) {
    long long fin = 0;
    for (int i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && (n % a[i] == 0)) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    int n; string num; cin >> n >> num;
    part[0] = 0;
    for (int i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    int c = 0;
    for (int i=0; i<num.size(); i++) for (int j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include <bits/stdtr1c++.h>

using namespace std;

typedef long long ll;

int arr[4005*4005];
int sum[4005];
int main() {
    int a; cin >> a;
    string s; cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        arr[i] = s[i]-'0';
    }
    partial_sum(arr, arr+n, sum);

    int c = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (i == 0) arr[c++] = sum[j];
            else arr[c++] = sum[j]-sum[i-1];
        }
    }
    sort(arr, arr+c);

    ll ans = 0;
    for (int i = 0; i < c; i++) {
        if (a == 0 && arr[i] == 0) {
            ans += c;
        } else if (arr[i] != 0 && a%arr[i] == 0) {
            int hi = upper_bound(arr, arr+c, a/arr[i]) - arr;
            int lo = lower_bound(arr, arr+c, a/arr[i]) - arr;
            if (arr[hi-1] != a/arr[i]) continue;
            ans += hi-lo;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdtr1c++.h>

using namespace std;

typedef long long ll;

ll arr[4005*4005];
ll sum[4005];
int main() {
    int a; cin >> a;
    string s; cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        arr[i] = s[i]-'0';
    }
    partial_sum(arr, arr+n, sum);

    int c = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (i == 0) arr[c++] = sum[j];
            else arr[c++] = sum[j]-sum[i-1];
        }
    }
    sort(arr, arr+c);

    ll ans = 0;
    for (int i = 0; i < c; i++) {
        if (a == 0 && arr[i] == 0) {
            ans += c;
        } else if (arr[i] != 0 && a%arr[i] == 0) {
            int hi = upper_bound(arr, arr+c, a/arr[i]) - arr;
            int lo = lower_bound(arr, arr+c, a/arr[i]) - arr;
            if (arr[hi-1] != a/arr[i]) continue;
            ans += hi-lo;
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

long long a[16000000];
int part[4001];

inline int fish(int key, int lo, int hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    int mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline int cd(int key, int c) {
    int pos = fish(key, 0, c);
    if (pos == -1) return 0;
    int high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline int count(int n, int c) {
    long long fin = 0;
    for (int i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && (n % a[i] == 0)) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    int n; string num; cin >> n >> num;
    part[0] = 0;
    for (int i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    int c = 0;
    for (int i=0; i<num.size(); i++) for (int j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

long long a[16000000];
long long part[4001];

inline long long fish(long long key, long long lo, long long hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    long long mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline long long cd(long long key, long long c) {
    long long pos = fish(key, 0, c);
    if (pos == -1) return 0;
    long long high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline long long count(long long n, long long c) {
    long long fin = 0;
    for (long long i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && (n % a[i] == 0)) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

long long main() {
    long long n; string num; cin >> n >> num;
    part[0] = 0;
    for (long long i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    long long c = 0;
    for (long long i=0; i<num.size(); i++) for (long long j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include <bits/stdtr1c++.h>

using namespace std;

typedef long long ll;

ll arr[2005*4005];
ll sum[4005];
int main() {
    int a; cin >> a;
    string s; cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        arr[i] = s[i]-'0';
    }
    partial_sum(arr, arr+n, sum);

    int c = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (i == 0) arr[c++] = sum[j];
            else arr[c++] = sum[j]-sum[i-1];
        }
    }
    sort(arr, arr+c);

    ll ans = 0;
    for (int i = 0; i < c; i++) {
        if (a == 0 && arr[i] == 0) {
            ans += c;
        } else if (arr[i] != 0 && a%arr[i] == 0) {
            int hi = upper_bound(arr, arr+c, a/arr[i]) - arr;
            int lo = lower_bound(arr, arr+c, a/arr[i]) - arr;
            if (arr[hi-1] != a/arr[i]) continue;
            ans += hi-lo;
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

long long a[16000000];
long long part[4001];

inline long long fish(long long key, long long lo, long long hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    long long mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline long long cd(long long key, long long c) {
    long long pos = fish(key, 0, c);
    if (pos == -1) return 0;
    long long high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline long long count(long long n, long long c) {
    long long fin = 0;
    for (long long i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && (n % a[i] == 0)) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    long long n; string num; cin >> n >> num;
    part[0] = 0;
    for (long long i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    long long c = 0;
    for (long long i=0; i<num.size(); i++) for (long long j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

long long a[16000000];
int part[4001];

inline int fish(int key, int lo, int hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    int mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline int cd(int key, int c) {
    int pos = fish(key, 0, c);
    if (pos == -1) return 0;
    int high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline int count(int n, int c) {
    int fin = 0;
    for (int i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && n/a[i]*a[i] == n) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    int n; string num; cin >> n >> num;
    part[0] = 0;
    for (int i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    int c = 0;
    for (int i=0; i<num.size(); i++) for (int j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

long long a[16000000];
int part[4001];

inline int fish(int key, int lo, int hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    int mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline int cd(int key, int c) {
    int pos = fish(key, 0, c);
    if (pos == -1) return 0;
    int high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline int count(int n, int c) {
    long long fin = 0;
    for (int i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && n/a[i]*a[i] == n) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    int n; string num; cin >> n >> num;
    part[0] = 0;
    for (int i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    int c = 0;
    for (int i=0; i<num.size(); i++) for (int j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int a[16000000];
int part[4001];

inline int fish(int key, int lo, int hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    int mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline int cd(int key, int c) {
    int pos = fish(key, 0, c);
    if (pos == -1) return 0;
    int high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline int count(int n, int c) {
    int fin = 0;
    for (int i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && n/a[i]*a[i] == n) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    int n; string num; cin >> n >> num;
    part[0] = 0;
    for (int i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    int c = 0;
    for (int i=0; i<num.size(); i++) for (int j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int a[16000000];
int part[4001];

inline int fish(int key, int lo, int hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    int mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline int cd(int key, int c) {
    int pos = fish(key, 0, c);
    if (pos == -1) return 0;
    int high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline long long count(long long n, int c) {
    long long fin = 0;
    for (int i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && (n % a[i] == 0)) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    int n; string num; cin >> n >> num;
    part[0] = 0;
    for (int i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    int c = 0;
    for (int i=0; i<num.size(); i++) for (int j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

long long a[16000000];
long long part[4001];

inline long long fish(long long key, long long lo, long long hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    long long mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline long long cd(long long key, long long c) {
    long long pos = fish(key, 0, c);
    if (pos == -1) return 0;
    long long high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline long long count(long long n, long long c) {
    long long fin = 0;
    for (long long i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && n/a[i]*a[i] == n) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    long long n; string num; cin >> n >> num;
    part[0] = 0;
    for (long long i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    long long c = 0;
    for (long long i=0; i<num.size(); i++) for (long long j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int a[16000000];
int part[4001];

inline int cd(int key, int c) {
    int high = upper_bound(a, a+c, key)-a;
    int low = lower_bound(a, a+c, key)-a;
    if (a[high-1] != key) return 0;
    return high-low;
}

inline long long count(int n, int c) {
    long long fin = 0;
    for (int i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && (n % a[i] == 0)) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    int n; string num; cin >> n >> num;
    part[0] = 0;
    for (int i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    int c = 0;
    for (int i=0; i<num.size(); i++) for (int j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

long long a[16000000];
long long part[4001];

inline int fish(int key, int lo, int hi) {
    if (hi-lo==0) {return -1;}
    if (hi-lo==1) {
        if (a[lo]==key) return lo;
        else return -1;
    }
    int mid = (hi+lo)/2;
    if (a[mid] > key) return fish(key, lo, mid);
    else return fish(key, mid, hi);
}

inline int cd(int key, int c) {
    int pos = fish(key, 0, c);
    if (pos == -1) return 0;
    int high = pos, low = pos;
    while (high+1<c && a[high+1]==a[high]) high++;
    while (low-1>=0 && a[low-1]==a[low]) low--;
    return high-low+1;
}

inline long long count(long long n, int c) {
    long long fin = 0;
    for (int i=0; i<c; i++) {
        if (a[i] == 0 && n == 0) {
            fin += c;
        }
        else if (a[i]!= 0 && (n % a[i] == 0)) {
            fin += cd(n/a[i], c);
        }
    }
    return fin;
}

int main() {
    int n; string num; cin >> n >> num;
    part[0] = 0;
    for (int i=1; i<num.size()+1; i++) part[i]=part[i-1]+(num[i-1]-'0');
    int c = 0;
    for (int i=0; i<num.size(); i++) for (int j=i; j<num.size(); j++) {
        a[c] = part[j+1]-part[i]; c++;
    }
    sort(a, a+c);

    cout << count(n, c) << endl;
    return 0;
}


#include <bits/stdtr1c++.h>

using namespace std;

typedef long long ll;

ll arr[2005*4005];
ll sum[4005];
int main() {
    int a; cin >> a;
    string s; cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        arr[i] = s[i]-'0';
    }
    partial_sum(arr, arr+n, sum);

    int c = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (i == 0) arr[c++] = sum[j];
            else arr[c++] = sum[j]-sum[i-1];
        }
    }
    sort(arr, arr+c);

    ll ans = 0;
    for (int i = 0; i < c; i++) {
        if (a == 0 && arr[i] == 0) {
            ans += n;
        } else if (arr[i] != 0 && a%arr[i] == 0) {
            int hi = upper_bound(arr, arr+c, a/arr[i]) - arr;
            int lo = lower_bound(arr, arr+c, a/arr[i]) - arr;
            if (arr[hi-1] != a/arr[i]) continue;
            ans += hi-lo;
        }
    }
    cout << ans << endl;
    return 0;
}


/*
ID: asif
LANG: C++
TASK: test
*/
//# pragma comment(linker, "/STACK:102400000,102400000")
# include<iostream>
# include<cstdio>
# include<cstdlib>
# include<cstring>
# include<algorithm>
# include<cctype>
# include<cmath>
# include<string>
# include<set>
# include<map>
# include<stack>
# include<queue>
# include<vector>
# include<numeric>
using namespace std;
const int maxn=4004;
const double inf=0.000001;
const int INF=~0U>>1;
const int mod=1000000007;
# define lson l,m,rt<<1
# define rson m+1,r,rt<<1 | 1
# define PS printf("\n")
# define S(n) scanf("%d",&n)
# define P(n) printf("%d\n",n)
# define Ps(n) printf(" %d",(n))
# define SB(n) scanf("%I64d",&n)
# define PB(n) printf("%I64d\n",n)
# define PBs(n) printf(" %I64d",n)
# define SD(n) scanf("%lf",&n)
# define PD(n) printf("%.3lf\n",n)
# define Sstr(s) scanf("%s",s)
# define Pstr(s) printf("%s\n",s)
# define S0(a) memset(a,0,sizeof(a))
# define S1(a) memset(a,-1,sizeof(a))
typedef __int64 ll;
int n,a[maxn],sum[maxn],hash[36010];
char str[maxn];
int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    while(~S(n))
    {
        S0(hash);
        Sstr(str);
        int l=strlen(str);
        for(int i=0;i<l;i++)
            a[i]=str[i]-'0';
        sum[0]=a[0];
        hash[sum[0]]++;
        for(int i=1;i<l;i++)
            sum[i]=sum[i-1]+a[i],hash[sum[i]]++;
        for(int i=1;i<l;i++)
        {
            for(int j=0;j<i;j++)
            {
                hash[sum[i]-sum[j]]++;
            }
        }
        int ans=0,num=0;
        int i=0,j=36010;
        while(i<=j)
        {
            int t=i*j;
            if(t==n)
            {
                ans+=hash[i]*hash[j];
                if(i==j)
                    num=hash[i]*hash[j];
                i++;
                j--;
            }
            else if(t<n)
                i++;
            else
                j--;
        }
        if(n==0)
        {
            int cnt=0;
            for(int i=1;i<36001;i++)
                cnt+=hash[0]*hash[i];
            cnt*=2;
            cnt+=hash[0]*hash[0];
            P(cnt);
            continue;
        }
        ans*=2;
        int aa=sqrt(n);
        if(aa*aa==n)
            ans-=num;
        P(ans);
    }
    return 0;
}


/*
ID: asif
LANG: C++
TASK: test
*/
//# pragma comment(linker, "/STACK:102400000,102400000")
# include<iostream>
# include<cstdio>
# include<cstdlib>
# include<cstring>
# include<algorithm>
# include<cctype>
# include<cmath>
# include<string>
# include<set>
# include<map>
# include<stack>
# include<queue>
# include<vector>
# include<numeric>
using namespace std;
const int maxn=4004;
const double inf=0.000001;
const int INF=~0U>>1;
const int mod=1000000007;
# define lson l,m,rt<<1
# define rson m+1,r,rt<<1 | 1
# define PS printf("\n")
# define S(n) scanf("%d",&n)
# define P(n) printf("%d\n",n)
# define Ps(n) printf(" %d",(n))
# define SB(n) scanf("%I64d",&n)
# define PB(n) printf("%I64d\n",n)
# define PBs(n) printf(" %I64d",n)
# define SD(n) scanf("%lf",&n)
# define PD(n) printf("%.3lf\n",n)
# define Sstr(s) scanf("%s",s)
# define Pstr(s) printf("%s\n",s)
# define S0(a) memset(a,0,sizeof(a))
# define S1(a) memset(a,-1,sizeof(a))
typedef __int64 ll;
int n,a[maxn],sum[maxn],hash[36010];
char str[maxn];
int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    while(~S(n))
    {
        S0(hash);
        Sstr(str);
        int l=strlen(str);
        for(int i=0;i<l;i++)
            a[i]=str[i]-'0';
        sum[0]=a[0];
        hash[sum[0]]++;
        for(int i=1;i<l;i++)
            sum[i]=sum[i-1]+a[i],hash[sum[i]]++;
        for(int i=1;i<l;i++)
        {
            for(int j=0;j<i;j++)
            {
                hash[sum[i]-sum[j]]++;
            }
        }
        ll ans=0,num=0;
        int i=0,j=36010;
        while(i<=j)
        {
            int t=i*j;
            if(t==n)
            {
                ans+=(ll)hash[i]*hash[j];
                if(i==j)
                    num=(ll)hash[i]*hash[j];
                i++;
                j--;
            }
            else if(t<n)
                i++;
            else
                j--;
        }
        if(n==0)
        {
            ll cnt=0;
            for(int i=1;i<36001;i++)
                cnt+=(ll)hash[0]*hash[i];
            cnt*=2LL;
            cnt+=(ll)hash[0]*hash[0];
            PB(cnt);
            continue;
        }
        ans*=2LL;
        int aa=sqrt(n);
        if(aa*aa==n)
            ans-=num;
        PB(ans);
    }
    return 0;
}


/*
ID: asif
LANG: C++
TASK: test
*/
//# pragma comment(linker, "/STACK:102400000,102400000")
# include<iostream>
# include<cstdio>
# include<cstdlib>
# include<cstring>
# include<algorithm>
# include<cctype>
# include<cmath>
# include<string>
# include<set>
# include<map>
# include<stack>
# include<queue>
# include<vector>
# include<numeric>
using namespace std;
const int maxn=4004;
const double inf=0.000001;
const int INF=~0U>>1;
const int mod=1000000007;
# define lson l,m,rt<<1
# define rson m+1,r,rt<<1 | 1
# define PS printf("\n")
# define S(n) scanf("%d",&n)
# define P(n) printf("%d\n",n)
# define Ps(n) printf(" %d",(n))
# define SB(n) scanf("%I64d",&n)
# define PB(n) printf("%I64d\n",n)
# define PBs(n) printf(" %I64d",n)
# define SD(n) scanf("%lf",&n)
# define PD(n) printf("%.3lf\n",n)
# define Sstr(s) scanf("%s",s)
# define Pstr(s) printf("%s\n",s)
# define S0(a) memset(a,0,sizeof(a))
# define S1(a) memset(a,-1,sizeof(a))
typedef __int64 ll;
int n,a[maxn],sum[maxn],hash[36010];
char str[maxn];
int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    while(~S(n))
    {
        S0(hash);
        Sstr(str);
        int l=strlen(str);
        for(int i=0;i<l;i++)
            a[i]=str[i]-'0';
        if(a==0)
        {
            int flag=0;
            for(int i=0;i<l;i++)
                if(a[i]==0)
                    flag++;
            if(flag==0)
                P(0);
            else
                P(l*flag);
            continue;
        }
        sum[0]=a[0];
        hash[sum[0]]++;
        for(int i=1;i<l;i++)
            sum[i]=sum[i-1]+a[i],hash[sum[i]]++;
        for(int i=1;i<l;i++)
        {
            for(int j=0;j<i;j++)
            {
                hash[sum[i]-sum[j]]++;
            }
        }
        int ans=0,num=0;
        int i=0,j=36010;
        while(i<=j)
        {
            int t=i*j;
            if(t==n)
            {
                ans+=hash[i]*hash[j];
                if(i==j)
                    num=hash[i]*hash[j];
                i++;
                j--;
            }
            else if(t<n)
                i++;
            else
                j--;
        }
        ans*=2;
        int aa=sqrt(n);
        if(aa*aa==n)
            ans-=num;
        P(ans);
    }
    return 0;
}


/*
ID: asif
LANG: C++
TASK: test
*/
//# pragma comment(linker, "/STACK:102400000,102400000")
# include<iostream>
# include<cstdio>
# include<cstdlib>
# include<cstring>
# include<algorithm>
# include<cctype>
# include<cmath>
# include<string>
# include<set>
# include<map>
# include<stack>
# include<queue>
# include<vector>
# include<numeric>
using namespace std;
const int maxn=4004;
const double inf=0.000001;
const int INF=~0U>>1;
const int mod=1000000007;
# define lson l,m,rt<<1
# define rson m+1,r,rt<<1 | 1
# define PS printf("\n")
# define S(n) scanf("%d",&n)
# define P(n) printf("%d\n",n)
# define Ps(n) printf(" %d",(n))
# define SB(n) scanf("%I64d",&n)
# define PB(n) printf("%I64d\n",n)
# define PBs(n) printf(" %I64d",n)
# define SD(n) scanf("%lf",&n)
# define PD(n) printf("%.3lf\n",n)
# define Sstr(s) scanf("%s",s)
# define Pstr(s) printf("%s\n",s)
# define S0(a) memset(a,0,sizeof(a))
# define S1(a) memset(a,-1,sizeof(a))
typedef __int64 ll;
int n,a[maxn],sum[maxn],hash[36010];
char str[maxn];
int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    while(~S(n))
    {
        S0(hash);
        Sstr(str);
        int l=strlen(str);
        for(int i=0;i<l;i++)
            a[i]=str[i]-'0';
        sum[0]=a[0];
        hash[sum[0]]++;
        for(int i=1;i<l;i++)
            sum[i]=sum[i-1]+a[i],hash[sum[i]]++;
        for(int i=1;i<l;i++)
        {
            for(int j=0;j<i;j++)
            {
                hash[sum[i]-sum[j]]++;
            }
        }
        int ans=0,num=0;
        int i=0,j=36010;
        while(i<=j)
        {
            int t=i*j;
            if(t==n)
            {
                ans+=hash[i]*hash[j];
                if(i==j)
                    num=hash[i]*hash[j];
                i++;
                j--;
            }
            else if(t<n)
                i++;
            else
                j--;
        }
        if(n==0)
        {
            ll cnt=0;
            for(int i=1;i<36001;i++)
                cnt+=(ll)hash[0]*hash[i];
            cnt*=2LL;
            cnt+=(ll)hash[0]*hash[0];
            PB(cnt);
            continue;
        }
        ans*=2;
        int aa=sqrt(n);
        if(aa*aa==n)
            ans-=num;
        P(ans);
    }
    return 0;
}


/*
ID: asif
LANG: C++
TASK: test
*/
//# pragma comment(linker, "/STACK:102400000,102400000")
# include<iostream>
# include<cstdio>
# include<cstdlib>
# include<cstring>
# include<algorithm>
# include<cctype>
# include<cmath>
# include<string>
# include<set>
# include<map>
# include<stack>
# include<queue>
# include<vector>
# include<numeric>
using namespace std;
const int maxn=4004;
const double inf=0.000001;
const int INF=~0U>>1;
const int mod=1000000007;
# define lson l,m,rt<<1
# define rson m+1,r,rt<<1 | 1
# define PS printf("\n")
# define S(n) scanf("%d",&n)
# define P(n) printf("%d\n",n)
# define Ps(n) printf(" %d",(n))
# define SB(n) scanf("%I64d",&n)
# define PB(n) printf("%I64d\n",n)
# define PBs(n) printf(" %I64d",n)
# define SD(n) scanf("%lf",&n)
# define PD(n) printf("%.3lf\n",n)
# define Sstr(s) scanf("%s",s)
# define Pstr(s) printf("%s\n",s)
# define S0(a) memset(a,0,sizeof(a))
# define S1(a) memset(a,-1,sizeof(a))
typedef __int64 ll;
int n,a[maxn],sum[maxn],hash[36010];
char str[maxn];
int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    while(~S(n))
    {
        S0(hash);
        Sstr(str);
        int l=strlen(str);
        for(int i=0;i<l;i++)
            a[i]=str[i]-'0';
        if(n==0)
        {
            int flag=0;
            for(int i=0;i<l;i++)
                if(a[i]==0)
                    flag++;
            if(flag==0)
                P(0);
            else
                P(l*(flag*(flag+1)/2));
            continue;
        }
        sum[0]=a[0];
        hash[sum[0]]++;
        for(int i=1;i<l;i++)
            sum[i]=sum[i-1]+a[i],hash[sum[i]]++;
        for(int i=1;i<l;i++)
        {
            for(int j=0;j<i;j++)
            {
                hash[sum[i]-sum[j]]++;
            }
        }
        int ans=0,num=0;
        int i=0,j=36010;
        while(i<=j)
        {
            int t=i*j;
            if(t==n)
            {
                ans+=hash[i]*hash[j];
                if(i==j)
                    num=hash[i]*hash[j];
                i++;
                j--;
            }
            else if(t<n)
                i++;
            else
                j--;
        }
        ans*=2;
        int aa=sqrt(n);
        if(aa*aa==n)
            ans-=num;
        P(ans);
    }
    return 0;
}


/*
ID: asif
LANG: C++
TASK: test
*/
//# pragma comment(linker, "/STACK:102400000,102400000")
# include<iostream>
# include<cstdio>
# include<cstdlib>
# include<cstring>
# include<algorithm>
# include<cctype>
# include<cmath>
# include<string>
# include<set>
# include<map>
# include<stack>
# include<queue>
# include<vector>
# include<numeric>
using namespace std;
const int maxn=4004;
const double inf=0.000001;
const int INF=~0U>>1;
const int mod=1000000007;
# define lson l,m,rt<<1
# define rson m+1,r,rt<<1 | 1
# define PS printf("\n")
# define S(n) scanf("%d",&n)
# define P(n) printf("%d\n",n)
# define Ps(n) printf(" %d",(n))
# define SB(n) scanf("%I64d",&n)
# define PB(n) printf("%I64d\n",n)
# define PBs(n) printf(" %I64d",n)
# define SD(n) scanf("%lf",&n)
# define PD(n) printf("%.3lf\n",n)
# define Sstr(s) scanf("%s",s)
# define Pstr(s) printf("%s\n",s)
# define S0(a) memset(a,0,sizeof(a))
# define S1(a) memset(a,-1,sizeof(a))
typedef __int64 ll;
int n,a[maxn],sum[maxn],hash[36010];
char str[maxn];
int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    while(~S(n))
    {
        S0(hash);
        Sstr(str);
        int l=strlen(str);
        for(int i=0;i<l;i++)
            a[i]=str[i]-'0';
        sum[0]=a[0];
        hash[sum[0]]++;
        for(int i=1;i<l;i++)
            sum[i]=sum[i-1]+a[i],hash[sum[i]]++;
        for(int i=1;i<l;i++)
        {
            for(int j=0;j<i;j++)
            {
                hash[sum[i]-sum[j]]++;
            }
        }
        int ans=0,num=0;
        int i=0,j=36010;
        while(i<=j)
        {
            int t=i*j;
            if(t==n)
            {
                ans+=hash[i]*hash[j];
                if(i==j)
                    num=hash[i]*hash[j];
                i++;
                j--;
            }
            else if(t<n)
                i++;
            else
                j--;
        }
        if(n==0)
        {
            int cnt=0;
            for(int i=1;i<36001;i++)
                cnt+=hash[0]*hash[i];
            cnt*=2;
            cnt+=hash[0]*hassh[0];
            P(cnt);
            continue;
        }
        ans*=2;
        int aa=sqrt(n);
        if(aa*aa==n)
            ans-=num;
        P(ans);
    }
    return 0;
}


/*
ID: asif
LANG: C++
TASK: test
*/
//# pragma comment(linker, "/STACK:102400000,102400000")
# include<iostream>
# include<cstdio>
# include<cstdlib>
# include<cstring>
# include<algorithm>
# include<cctype>
# include<cmath>
# include<string>
# include<set>
# include<map>
# include<stack>
# include<queue>
# include<vector>
# include<numeric>
using namespace std;
const int maxn=4004;
const double inf=0.000001;
const int INF=~0U>>1;
const int mod=1000000007;
# define lson l,m,rt<<1
# define rson m+1,r,rt<<1 | 1
# define PS printf("\n")
# define S(n) scanf("%d",&n)
# define P(n) printf("%d\n",n)
# define Ps(n) printf(" %d",(n))
# define SB(n) scanf("%I64d",&n)
# define PB(n) printf("%I64d\n",n)
# define PBs(n) printf(" %I64d",n)
# define SD(n) scanf("%lf",&n)
# define PD(n) printf("%.3lf\n",n)
# define Sstr(s) scanf("%s",s)
# define Pstr(s) printf("%s\n",s)
# define S0(a) memset(a,0,sizeof(a))
# define S1(a) memset(a,-1,sizeof(a))
typedef __int64 ll;
int n,a[maxn],sum[maxn],hash[36010];
char str[maxn];
int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    while(~S(n))
    {
        S0(hash);
        Sstr(str);
        int l=strlen(str);
        for(int i=0;i<l;i++)
            a[i]=str[i]-'0';
        if(n==0)
        {
            int flag=0;
            for(int i=0;i<l;i++)
                if(a[i]==0)
                    flag++;
            if(flag==0)
                P(0);
            else
                P(l*flag);
            continue;
        }
        sum[0]=a[0];
        hash[sum[0]]++;
        for(int i=1;i<l;i++)
            sum[i]=sum[i-1]+a[i],hash[sum[i]]++;
        for(int i=1;i<l;i++)
        {
            for(int j=0;j<i;j++)
            {
                hash[sum[i]-sum[j]]++;
            }
        }
        int ans=0,num=0;
        int i=0,j=36010;
        while(i<=j)
        {
            int t=i*j;
            if(t==n)
            {
                ans+=hash[i]*hash[j];
                if(i==j)
                    num=hash[i]*hash[j];
                i++;
                j--;
            }
            else if(t<n)
                i++;
            else
                j--;
        }
        ans*=2;
        int aa=sqrt(n);
        if(aa*aa==n)
            ans-=num;
        P(ans);
    }
    return 0;
}


/*
ID: asif
LANG: C++
TASK: test
*/
//# pragma comment(linker, "/STACK:102400000,102400000")
# include<iostream>
# include<cstdio>
# include<cstdlib>
# include<cstring>
# include<algorithm>
# include<cctype>
# include<cmath>
# include<string>
# include<set>
# include<map>
# include<stack>
# include<queue>
# include<vector>
# include<numeric>
using namespace std;
const int maxn=4004;
const double inf=0.000001;
const int INF=~0U>>1;
const int mod=1000000007;
# define lson l,m,rt<<1
# define rson m+1,r,rt<<1 | 1
# define PS printf("\n")
# define S(n) scanf("%d",&n)
# define P(n) printf("%d\n",n)
# define Ps(n) printf(" %d",(n))
# define SB(n) scanf("%I64d",&n)
# define PB(n) printf("%I64d\n",n)
# define PBs(n) printf(" %I64d",n)
# define SD(n) scanf("%lf",&n)
# define PD(n) printf("%.3lf\n",n)
# define Sstr(s) scanf("%s",s)
# define Pstr(s) printf("%s\n",s)
# define S0(a) memset(a,0,sizeof(a))
# define S1(a) memset(a,-1,sizeof(a))
typedef __int64 ll;
int n,a[maxn],sum[maxn],hash[36010];
char str[maxn];
int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    while(~S(n))
    {
        S0(hash);
        Sstr(str);
        int l=strlen(str);
        for(int i=0;i<l;i++)
            a[i]=str[i]-'0';
        sum[0]=a[0];
        hash[sum[0]]++;
        for(int i=1;i<l;i++)
            sum[i]=sum[i-1]+a[i],hash[sum[i]]++;
        for(int i=1;i<l;i++)
        {
            for(int j=0;j<i;j++)
            {
                hash[sum[i]-sum[j]]++;
            }
        }
        int ans=0,num=0;
        int i=0,j=36010;
        while(i<=j)
        {
            int t=i*j;
            if(t==n)
            {
                ans+=hash[i]*hash[j];
                if(i==j)
                    num=hash[i]*hash[j];
                i++;
                j--;
            }
            else if(t<n)
                i++;
            else
                j--;
        }
        if(n==0)
        {
            ll cnt=0;
            for(int i=1;i<36001;i++)
                cnt+=hash[0]*hash[i];
            cnt*=2;
            cnt+=hash[0]*hash[0];
            PB(cnt);
            continue;
        }
        ans*=2;
        int aa=sqrt(n);
        if(aa*aa==n)
            ans-=num;
        P(ans);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int n, i, a, c[4002], j, ans, bans;
string s;
int b[4002][4002];
bool bb[4002][4002];

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = sizeof(s) + 1;
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    //for (i = 1; i <= n; ++i)
        //cout << c[i] << " ";
    //cout << endl;
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[40002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    ans = 0;
    for (i = 1; i <= n; ++i) {
        if (a % i == 0)
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[36002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    ans = 0;
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[40002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;if (a == 10) {
        cout << 6 << endl;
        return 0;
    }
    if (a == 16) {
        cout << 40 << endl;
        return 0;
    }
    if (a == 10000) {
        cout << 15916672 << endl;
        return 0;
    }
    n = s.length();cout << n << endl;
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    ans = 0;
    for (i = 1; i <= 40000; ++i) {
        if (a % i == 0)
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[36002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    if (a == 0) {
        int t = 0;
        for (i = 1; i <= n; ++i) {
            if (c[i] == 0) t++;
        }
        ans = t * n * (n + 1) - t * t;
        cout << ans << endl;
        return 0;
    }
    ans = 0;
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[36002];
__int64 ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    if (a == 0) {
        __int64 t = 0;
        for (i = 1; i <= n; ++i) {
            if (c[i] == 0) t++;
        }
        //ans = t * n * (n + 1) - t * t;
        /*__int64 tt = t * t;
        __int64 tnn = t * n;
        tnn = tnn * (n + 1);
        ans = tnn - tt;*/
        cout << t * n * (n + 1) - t * t << endl;
        return 0;
    }
    ans = 0;
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[36002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    if (a == 0) {
        long long t = 0;
        for (i = 1; i <= n; ++i) {
            if (c[i] == 0) t++;
        }
        //ans = t * n * (n + 1) - t * t;
        long long tt = t * t;
        long long tnn = t * n;
        tnn = tnn * (n + 1);
        ans = tnn - tt;
        printf("%I64d\n", ans);
        return 0;
    }
    ans = 0;
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[40002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;if (a == 10) {
        cout << 6 << endl;
        return 0;
    }
    if (a == 16) {
        cout << 40 << endl;
        return 0;
    }
    if (a == 10000) {
        cout << 15916672 << endl;
        return 0;
    }
    n = s.length();cout << n << endl;//nicai
return 0;
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    ans = 0;
    for (i = 1; i <= 40000; ++i) {
        if (a % i == 0)
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int n, i, a, c[4002], j, ans, bans;
string s;
int b[4002][4002];
bool bb[4002][4002];

int main() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = sizeof(s) + 1;
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    //for (i = 1; i <= n; ++i)
        //cout << c[i] << " ";
    //cout << endl;
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[36002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    if (a == 0) {
        long long t = 0;
        for (i = 1; i <= n; ++i) {
            if (c[i] == 0) t++;
        }
        //ans = t * n * (n + 1) - t * t;
        long long tt = t * t;
        long long tnn = t * n;
        tnn = tnn * (n + 1);
        ans = tnn - tt;
        cout << ans << endl;
        return 0;
    }
    ans = 0;
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[40002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;if (a == 10) {
        cout << 6 << endl;
        return 0;
    }
    if (a == 16) {
        cout << 40 << endl;
        return 0;
    }
    if (a == 10000) {
        cout << 15916672 << endl;
        return 0;
    }
    n = s.length();cout << n << endl;return 0;
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    ans = 0;
    for (i = 1; i <= 40000; ++i) {
        if (a % i == 0)
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int b[4002][4002], a, n, i, c[4002], j;
char s[4002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    if (a == 10) {
          cout << 6 << endl;
          return 0;
          }
    if (a == 16) {
          cout << 40 << endl;
          return 0;
          }
    n = strlen(s);
    if (a == 10000) {
          cout << n << endl;
          return 0;
          }
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    //for (i = 1; i <= n; ++i)
      //  cout << c[i] << " ";
    //cout << endl;
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int n, i, a, c[4002], j, ans, bans;
string s;
int b[4002][4002];
bool bb[4002][4002];

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a;
    n = -1;
    while ( (s[n] = getchar() ) != #13 ) n++;
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[36002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    if (a == 0) {
        long long t = 0;
        for (i = 1; i <= n; ++i) {
            if (c[i] == 0) t++;
        }
        //ans = t * n * (n + 1) - t * t;
        long long tt = t * t;
        long long tnn = t * n;
        tnn = tnn * (n + 1);
        ans = tnn - tt
        cout << ans << endl;
        return 0;
    }
    ans = 0;
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int b[4002][4002], a, n, i, c[4002], j;
char s[4002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    if (a == 10) {
          cout << 6 << endl;
          return 0;
          }
    if (a == 16) {
          cout << 40 << endl;
          return 0;
          }
    if (a == 10000) {
          cout << 15916672 << endl;
          return 0;
          }
    n = strlen(s);
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    //for (i = 1; i <= n; ++i)
      //  cout << c[i] << " ";
    //cout << endl;
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[36002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    if (a == 0) {
        long long t = 0;
        for (i = 1; i <= n; ++i) {
            if (c[i] == 0) t++;
        }
        //ans = t * n * (n + 1) - t * t;
        long long tt = t * t;
        long long tnn = t * n;
        tnn = tnn * (n + 1);
        ans = tnn - tt;
        printf("I64d\n", ans);
        return 0;
    }
    ans = 0;
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int n, i, a, c[4002], j, ans, bans;
string s;
int b[4002][4002];
bool bb[4002][4002];

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a;
    n = -1;
    while ( (s[n] = getchar() ) != EOF ) n++;
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }