#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p,len,num,dp[1000005],pre[1000005],cnt;
string s;
int main(){
cin>>p>>s;
len=s.size();
for(int i=0;i<len;i++){
num=(s[i]-'0')%p;
for(int j=0;j<p;j++){
dp[j]=0;
}
for(int j=0;j<p;j++){
dp[(j*10+num)%p]+=pre[j];
}
dp[num]++;
for(int j=0;j<p;j++){
pre[j]=dp[j];
}
cnt+=dp[0];
}
cout<<cnt;
return 0;
}
help me!!!