Language: C++

/*input
20 11
33883322005544116655
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
    ll ans=1;
    while(m){
        if(m%2){
            ans*=a;
            ans%=(mod);
        }
        a=(a*a)%(mod);
        m>>=1;
    }
    return ans;
}


void init(long long* a,long long n,long long val){
    for(long long i=0;i<n;i++)
        a[i]=val;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    ll t=1,i,j;
    ll n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    ll ans=0;
    if(p==2||p==5){
        rep(i,0,n){
            if((s[i]-48)%p)continue;
            ans+=(i+1);
        }
    }else{
        ll m[p]={0},k=0;
        m[0]=1;
        rep(i,0,n){
            k*=10;
            k%=p;
            k+=(s[i]-48);
            k%=p;
            ans+=m[k];
            m[k]++;
        }   
    }   
    cout<<ans<<endl;
    return 0;
}


/*input
20 11
33883322005544116655
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
    ll ans=1;
    while(m){
        if(m%2){
            ans*=a;
            ans%=(mod);
        }
        a=(a*a)%(mod);
        m>>=1;
    }
    return ans;
}


void init(long long* a,long long n,long long val){
    for(long long i=0;i<n;i++)
        a[i]=val;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    ll t=1,i,j;
    ll n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    ll ans=0;
    if(p==2||p==5){
        rep(i,0,n){
            if((s[i]-48)%p)continue;
            ans+=(i+1);
        }
    }else{
        ll m[p]={0},k=0;
        m[0]=1;
        rep(i,0,n){
            k*=10;
            k%=p;
            k+=(s[i]-48);
            k%=p;
            ans+=m[k];
            m[k]++;
        }   
    }   
    cout<<ans<<endl;
    return 0;
}




Compiler output:
a.cc:121:4: error: redefinition of 'long long int power(long long int, long long int, long long int)'
  121 | ll power(ll a,ll m,ll mod){
      |    ^~~~~
a.cc:34:4: note: 'long long int power(long long int, long long int, long long int)' previously defined here
   34 | ll power(ll a,ll m,ll mod){
      |    ^~~~~
a.cc:135:6: error: redefinition of 'void init(long long int*, long long int, long long int)'
  135 | void init(long long* a,long long n,long long val){
      |      ^~~~
a.cc:48:6: note: 'void init(long long int*, long long int, long long int)' previously defined here
   48 | void init(long long* a,long long n,long long val){
      |      ^~~~
a.cc:142:5: error: redefinition of 'int main()'
  142 | int main()
      |     ^~~~
a.cc:55:5: note: 'int main()' previously defined here
   55 | int main()
      |     ^~~~