Language: C++

#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, p;
    string s;
    cin >> n >> p >> s;
    ll ans == 0;
    if (p == 2) {
        REP(i, n) if ((int)(s[i] - '0')
% 2 == 0) ans += i + 1;
        cout << ans << endl;
        return;
    } else if (p == 5) {
        REP(i, n) if ((int)(s[i] - '0')
% 5 == 0) ans += i + 1;
        cout << ans << endl;
        return;
    }
    vi r(n);
    int d = 1;
    r[n - 1] = (int)(s[n - 1] - '0') % p;
    for (int i = n - 2; i >= 0; i--) {
        d = (d * 10) % p;
        r[i] = (r[i + 1] + (int)(s[i] - '0') * d) % p;
    }
    // printv(r);
    map<int, ll> m;
    m[0]++;
    for (auto q : r) m[q]++;
    for (auto e : m) if (e.second > 1) ans += e.second * (e.second - 1) / 2;
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:44:12: error: expected initializer before '==' token
   44 |     ll ans == 0;
      |            ^~
a.cc:47:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   47 | % 2 == 0) ans += i + 1;
      |           ^~~
      |           abs
a.cc:48:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   48 |         cout << ans << endl;
      |                 ^~~
      |                 abs
a.cc:52:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   52 | % 5 == 0) ans += i + 1;
      |           ^~~
      |           abs
a.cc:53:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   53 |         cout << ans << endl;
      |                 ^~~
      |                 abs
a.cc:67:40: error: 'ans' was not declared in this scope; did you mean 'abs'?
   67 |     for (auto e : m) if (e.second > 1) ans += e.second * (e.second - 1) / 2;
      |                                        ^~~
      |                                        abs
a.cc:68:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   68 |     cout << ans << endl;
      |             ^~~
      |             abs