import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container;

int n, p;
string s;

long solve() {
  long count;
  int[] mod = new int[n];
  for(int i=0; i<s.length; i++) {
    mod[i] = (s[i] - '0') % p;
  }
  for(int i=0; i<s.length; i++) {
    int m = 0;
    for(int j=i; j<s.length; j++) {
      m = (m*10+mod[j]) % p;
      if(m==0) count++;
    }
  }
  return count;
}

void main() {
  readf("%d %d\n", &n, &p);
  s = readln.chomp;
  writeln(solve);
}

