#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define printV(v) for(int i=0;i<v.size();i++){cout << v[i] << " ";} cout << endl
#define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
#define sortV(v) sort(v.begin(),v.end())
ll a,b,c,d,e,f,g,n,m,k,t,p;

ll mod = 1000000007;


struct LCA {
    vector<int> height, euler, first, segtree;
    vector<bool> visited;
    int n;
 
    LCA(vector<vector<int>> &adj, int root = 0) {
        n = adj.size();
        height.resize(n);
        first.resize(n);
        euler.reserve(n * 2);
        visited.assign(n, false);
        dfs(adj, root);
        int m = euler.size();
        segtree.resize(m * 4);
        build(1, 0, m - 1);
    }
 
    void dfs(vector<vector<int>> &adj, int node, int h = 0) {
        visited[node] = true;
        height[node] = h;
        first[node] = euler.size();
        euler.push_back(node);
        for (auto to : adj[node]) {
            if (!visited[to]) {
                dfs(adj, to, h + 1);
                euler.push_back(node);
            }
        }
    }
 
    void build(int node, int b, int e) {
        if (b == e) {
            segtree[node] = euler[b];
        } else {
            int mid = (b + e) / 2;
            build(node << 1, b, mid);
            build(node << 1 | 1, mid + 1, e);
            int l = segtree[node << 1], r = segtree[node << 1 | 1];
            segtree[node] = (height[l] < height[r]) ? l : r;
        }
    }
 
    int query(int node, int b, int e, int L, int R) {
        if (b > R || e < L)
            return -1;
        if (b >= L && e <= R)
            return segtree[node];
        int mid = (b + e) >> 1;
 
        int left = query(node << 1, b, mid, L, R);
        int right = query(node << 1 | 1, mid + 1, e, L, R);
        if (left == -1) return right;
        if (right == -1) return left;
        return height[left] < height[right] ? left : right;
    }
 
    int lca(int u, int v) {
        int left = first[u], right = first[v];
        if (left > right)
            swap(left, right);
        return query(1, 0, euler.size() - 1, left, right);
    }
};
 
 
ll dp[200002];


ll pw(ll begin, ll p){
        //cout << answer << " " << p << endl;
        ll answer = 1;
        while(p != 0){
            //cout << answer << " " << p <<" " << begin << endl;
            if(p % 2 == 0){
                begin = (begin * begin) % mod;
                p = p/2;
            }else{ 
                p--;
                answer = ((answer % mod) * (begin % mod))%mod;
            }
        }
       return answer;
}



void solve(){
    int size,k;
    map<ll, ll> mp;
    cin >> size >> k;
    mod = k;
    string str; cin >> str;
     ll cnt = 0;
    if(mod == 2 || mod == 5){
        for(int i=0;i<size;i++){
            a = str[i] - '0';
            if(a % mod == 0)
                cnt += (i+1);
        }
        cout << cnt;
        return;
    }
    //reverse(str.begin(),str.end());
    for(int i=size;i>=1;i--){
        a = str[i-1] - '0';
        a = (a * pw(10,size-i) + dp[i+1])%mod;
        dp[i] = a;
        mp[a]++;
    }
   
    for(auto it : mp){
       // cout << it.first << " " << it.second << endl;
        if(it.first > 0){
            cnt =cnt+ (it.second * (it.second-1 ))/2;
        }
        else cnt = cnt + (it.second * (it.second + 1))/2;
    }
    
    cout << cnt;
}

int main(){
    ios_base::sync_with_stdio(false);
    
    int cases = 1; 
    //cin >> cases;

    while(cases--){
        solve();
    }
    return 0;

}

Measured memory_bytes: 2580