Language: C++

#include<bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define N 100010
 
typedef double lf;
typedef long long ll;
#define int ll
typedef long double ld;
typedef unsigned long long ull;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef vector<pair<ll,ll > >vpll;
typedef vector<vll > vvll;
#define endl "\n"
#define sd(a) scanf("%d",&a)
#define sstr(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define debug(a) printf("check%d\n",a)
#define clr(a) memset(a,0,sizeof(a))
#define rtn return 
#define gc getchar
#define pb push_back
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define lp(i,b) for(ll i = ll(0); i<ll(b) ; i++) 
#define lpit(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define mid(s,e) (s+(e-s)/2)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define fast ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0);
ll ip(){
  ll x = 0; bool isNeg = false; char c;
  c = gc();
  if(c == '-')  isNeg = true , c = gc();
  for( ; c >= '0'  && c <= '9' ; c = gc()); x = (x << 1) + (x << 3) + c - '0';
  if(isNeg) x *= -1;  return x;
}
//////////////////////////////////////////// CONTAINERS FOR FUNCTIONS MENTIONED IN TEMPLATE ///////////////////////////////////
#define MAX 100005
//bool isPrime[MAX];
//int spf[MAX];
//////////////////////////////////////////// FUNCTIONS THAT NEED COMMENTED OUT CONTAINERS ////////////////////////////////////
 
 
//void prime_sieve(){ for(ll i=2 ; i*i<=MAX ; i++){ if(!isPrime[i]){ for(ll j=i*i ; j<=MAX ; j+=i)  isPrime[j] = 1;} }  }
//void spf_sieve(){ for(ll i=2 ; i<MAX ; i+=2)  spf[i] = 2;
//  for(ll i=3 ; i<MAX ; i+=2){ if(!isPrime[i]){ spf[i] = i; for(ll j=i ; (j*i)<MAX ; j+=2){ if(!isPrime[i*j])  isPrime[i*j] = true , spf[i*j] = i; } } }
//}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// inline ll ncr(ll n,ll r){ ll ans = 1 ; if(r > n-r) r = n-r; lp(i,r+1){ans*=(n-i) ; ans/=(i+1); } rtn ans; }
inline ll gcd(ll a,ll b){if(!a) rtn b; rtn gcd(b%a,a); }
inline ll fme(ll x,ll n){ll ans=1;x%=MOD;while(n>0){if(n&1){ ans*=x;ans%=MOD;} x*=x;x%=MOD;n>>=1;}rtn ans%MOD;}
inline bool isPalin(string &s){ int len = s.size()-1;lp(i,(len/2)+2){if(!(s[i]==s[len-i]))  rtn false;} rtn true;}
inline ll lcm(ll a,ll b){rtn (a*b)/gcd(a,b); }
inline ll fmm(ll a,ll b) {ll r=0;a%=MOD;b%=MOD;while(b>0){if(b&1){r+=a;r%=MOD;}a+=a;a%=MOD;b>>=1;}rtn r%MOD;}
inline ll sfme(ll a,ll b) {ll r=1;a%=MOD;while(b>0){if(b&1)r=fmm(r,a);a=fmm(a,a);b>>=1;}rtn r%MOD;}
inline int in(){ int NR=0; register char c=gc(); while( c < 48 || c > 57 ){c=gc();} 
  while(c>47 && c< 58){ NR = (NR << 3) + (NR << 1) + (c - 48); c=gc();} return NR;
}
 
ll dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};


// gp_hash_table<int,int,my_hash> m;

//--------------------------------TEMPLATE ENDS HERE--------------------------------------------------//
#define NMAX 100005
#define LOGNMAX 20
int f[NMAX];
 
int power(int a,int b){if(b==0){return 1;}int s=power(a,b/2);s*=s;s%=MOD;if(b&1){return (s*a)%MOD;}return s;}
 
int inv(int a){return power(a,MOD-2);}
 
int nCr(int n,int r){if(n<0 || r<0){return 0;}int ans=0;ans=f[n];ans*=inv(f[r]);ans%=MOD;ans*=inv(f[n-r]);ans%=MOD;return ans;}
 
int ncr(int n,int r){if(r==0){return 1;}if(n-r<r){r=n-r;}int ans=1;for(int i=0;i<r;i++){ans*=(n-i);ans/=(i+1);}return ans;}
 
int subCount(int arr[], int n, int k) 
{ 
    // create auxiliary hash array to count frequency 
    // of remainders 
    int mod[k]; 
    memset(mod, 0, sizeof(mod)); 
  
    // Traverse original array and compute cumulative 
    // sum take remainder of this current cumulative 
    // sum and increase count by 1 for this remainder 
    // in mod[] array 
    int cumSum = 0; 
    for (int i = 0; i < n; i++) { 
        cumSum += arr[i]; 
  
        // as the sum can be negative, taking modulo twice 
        mod[((cumSum % k) + k) % k]++; 
    } 
  
    int result = 0; // Initialize result 
  
    // Traverse mod[] 
    for (int i = 0; i < k; i++) 
  
        // If there are more than one prefix subarrays 
        // with a particular mod value. 
        if (mod[i] > 1) 
            result += (mod[i] * (mod[i] - 1)) / 2; 
  
    // add the elements which are divisible by k itself 
    // i.e., the elements whose sum = 0 
    result += mod[0]; 
  
    return result; 
} 
 
signed main(){
	fast;	
	// f[0]=1;
	// for(int i=1;i<NMAX;i++){
	// 	f[i]=(f[i-1]*i)%MOD;
	/
	
	int n,p;
	cin>>n>>p;
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	int ans=0;
	int pre[n];
	pre[0]=(s[0]-'0')%p;
	for(int i=1;i<n;i++){
		pre[i]=(pre[i-1]*10LL+(s[i]-'0'))%p;
	}
 
	map<int,int> my;
	for(int i=0;i<n;i++){
		if(pre[i]==0){
			my[pre[i]]++;
			ans+=my[pre[i]];
			continue;
		}
		ans+=my[pre[i]];
		my[pre[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'll in()':
a.cc:62:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   62 | inline int in(){ int NR=0; register char c=gc(); while( c < 48 || c > 57 ){c=gc();}
      |                                          ^
a.cc: In function 'int main()':
a.cc:125:9: error: expected primary-expression before '/' token
  125 |         /
      |         ^
a.cc:127:13: error: expected primary-expression before 'n'
  127 |         int n,p;
      |             ^
a.cc:128:14: error: 'n' was not declared in this scope; did you mean 'yn'?
  128 |         cin>>n>>p;
      |              ^
      |              yn
a.cc:128:17: error: 'p' was not declared in this scope; did you mean 'ip'?
  128 |         cin>>n>>p;
      |                 ^
      |                 ip
a.cc:134:9: error: 'pre' was not declared in this scope; did you mean 'pread'?
  134 |         pre[0]=(s[0]-'0')%p;
      |         ^~~
      |         pread