import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto P = s[1];
    auto S = readln.chomp;

    auto bucket = new long[](P);
    auto current = 10.to!int.iota.array;
    int offset = 0;

    long ans = 0;

    foreach (i; 0..N) {
        int d = (S[i] - '0') % P;
        bucket[current[d]] += 1;
        ans += bucket[current[0]];
        foreach (j; 0..10) current[j] = ((current[j] - d) % P + P) % P * powmod(10, P-2, P) % P;
    }

    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


