Language: C++

#include <bits/stdc++.h>

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

const int dx[]={1,-1,0,0},
		  dy[]={0,0,1,-1};

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int main(){
	IO();
	int p;
	scanf("%d %d",&n,&p);
	scanf("%s",s);
	int mod=0;
	ll ans=0;
	for(int i=0;s[i];i++){
		x=s[i]-'0';
		mod=(mod*10 + x)%p;
		if ((p==2 || p==5) && x%p==0)
			ans+=i+1;
		cnt[mod]++;
	}
	if (p==2 || p==5)
		return !printf("%lld\n",ans);
	for(int i=0;i<p;i++){
 		ans +=(ll)cnt[i]*(cnt[i]-1)/2;
	}
	printf("%lld\n",ans+cnt[0]);
}
#include <bits/stdc++.h>

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

const int dx[]={1,-1,0,0},
		  dy[]={0,0,1,-1};

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int main(){
	//IO();
	int p;
	scanf("%d %d",&n,&p);
	scanf("%s",s);
	int mod=0;
	ll ans=0;
	for(int i=0;s[i];i++){
		x=s[i]-'0';
		mod=(mod*10 + x)%p;
		if ((p==2 || p==5) && x%p==0)
			ans+=i+1;
		cnt[mod]++;
	}
	if (p==2 || p==5)
		return !printf("%lld\n",ans);
	for(int i=0;i<p;i++){
 		ans +=(ll)cnt[i]*(cnt[i]-1)/2;
	}
	printf("%lld\n",ans+cnt[0]);
}


Compiler output:
a.cc:55:11: error: redefinition of 'const int N'
   55 | const int N=1e6+3;
      |           ^
a.cc:5:11: note: 'const int N' previously defined here
    5 | const int N=1e6+3;
      |           ^
a.cc:57:14: error: redefinition of 'const double eps'
   57 | const double eps=0.000000001;
      |              ^~~
a.cc:7:14: note: 'const double eps' previously defined here
    7 | const double eps=0.000000001;
      |              ^~~
a.cc:63:11: error: redefinition of 'const int dx []'
   63 | const int dx[]={1,-1,0,0},
      |           ^~
a.cc:13:11: note: 'const int dx [4]' previously defined here
   13 | const int dx[]={1,-1,0,0},
      |           ^~
a.cc:64:19: error: redefinition of 'const int dy []'
   64 |                   dy[]={0,0,1,-1};
      |                   ^~
a.cc:14:19: note: 'const int dy [4]' previously defined here
   14 |                   dy[]={0,0,1,-1};
      |                   ^~
a.cc:66:11: error: redefinition of 'const int inf'
   66 | const int inf=1e9,mod=1e9+7;
      |           ^~~
a.cc:16:11: note: 'const int inf' previously defined here
   16 | const int inf=1e9,mod=1e9+7;
      |           ^~~
a.cc:66:19: error: redefinition of 'const int mod'
   66 | const int inf=1e9,mod=1e9+7;
      |                   ^~~
a.cc:16:19: note: 'const int mod' previously defined here
   16 | const int inf=1e9,mod=1e9+7;
      |                   ^~~
a.cc:68:5: error: redefinition of 'int n'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |     ^
a.cc:18:5: note: 'int n' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |     ^
a.cc:68:7: error: redefinition of 'int m'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |       ^
a.cc:18:7: note: 'int m' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |       ^
a.cc:68:9: error: redefinition of 'int a [1000003]'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |         ^
a.cc:18:9: note: 'int a [1000003]' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |         ^
a.cc:68:14: error: redefinition of 'int b [1000003]'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |              ^
a.cc:18:14: note: 'int b [1000003]' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |              ^
a.cc:68:19: error: redefinition of 'int k'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                   ^
a.cc:18:19: note: 'int k' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                   ^
a.cc:68:21: error: redefinition of 'int q'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                     ^
a.cc:18:21: note: 'int q' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                     ^
a.cc:68:23: error: redefinition of 'int u'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                       ^
a.cc:18:23: note: 'int u' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                       ^
a.cc:68:25: error: redefinition of 'int v'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                         ^
a.cc:18:25: note: 'int v' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                         ^
a.cc:68:27: error: redefinition of 'int x'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                           ^
a.cc:18:27: note: 'int x' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                           ^
a.cc:68:29: error: redefinition of 'int y'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                             ^
a.cc:18:29: note: 'int y' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                             ^
a.cc:68:31: error: redefinition of 'int tc'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                               ^~
a.cc:18:31: note: 'int tc' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                               ^~
a.cc:68:34: error: redefinition of 'int c'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                  ^
a.cc:18:34: note: 'int c' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                  ^
a.cc:68:36: error: redefinition of 'int l'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                    ^
a.cc:18:36: note: 'int l' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                    ^
a.cc:68:38: error: redefinition of 'int r'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                      ^
a.cc:18:38: note: 'int r' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                      ^
a.cc:68:40: error: redefinition of 'int ans'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                        ^~~
a.cc:18:40: note: 'int ans' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                        ^~~
a.cc:68:44: error: redefinition of 'int cnt [100005]'
   68 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                            ^~~
a.cc:18:44: note: 'int cnt [100005]' previously declared here
   18 | int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];
      |                                            ^~~
a.cc:70:6: error: redefinition of 'char s [1000003]'
   70 | char s[N];
      |      ^
a.cc:20:6: note: 'char s [1000003]' previously declared here
   20 | char s[N];
      |      ^
a.cc:72:6: error: redefinition of 'void IO()'
   72 | void IO(){
      |      ^~
a.cc:22:6: note: 'void IO()' previously defined here
   22 | void IO(){
      |      ^~
a.cc:80:5: error: redefinition of 'int main()'
   80 | int main(){
      |     ^~~~
a.cc:30:5: note: 'int main()' previously defined here
   30 | int main(){
      |     ^~~~