Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  int n,p;
  string s;
  cin >> n >> p >> s;
  ll ans;
  if (p == 2 || p == 5) {
    rep(i, n) {
      if (stoi(s.at(n-i-1)) == 0) {
        ans += n - i;
      }
    }
  } else {
    map<int,int> MP;
    int num;
    rep(i,n) {
      num += (stoi(s.at(n-i-1)) * 10 ** i) % p;
      num %= p;
      ans += map[num];
      if (num == 0) {
        ans++;
      }
      map[num] += 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:15: error: no matching function for call to 'stoi(__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type&)'
   13 |       if (stoi(s.at(n-i-1)) == 0) {
      |           ~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:4164:3: note: candidate: 'int std::__cxx11::stoi(const std::string&, std::size_t*, int)'
 4164 |   stoi(const string& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~
/usr/include/c++/14/bits/basic_string.h:4164:22: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'const std::string&' {aka 'const std::__cxx11::basic_string<char>&'}
 4164 |   stoi(const string& __str, size_t* __idx = 0, int __base = 10)
      |        ~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:4432:3: note: candidate: 'int std::__cxx11::stoi(const std::wstring&, std::size_t*, int)'
 4432 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~
/usr/include/c++/14/bits/basic_string.h:4432:23: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'const std::wstring&' {aka 'const std::__cxx11::basic_string<wchar_t>&'}
 4432 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |        ~~~~~~~~~~~~~~~^~~~~
a.cc:21:19: error: no matching function for call to 'stoi(__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type&)'
   21 |       num += (stoi(s.at(n-i-1)) * 10 ** i) % p;
      |               ~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4164:3: note: candidate: 'int std::__cxx11::stoi(const std::string&, std::size_t*, int)'
 4164 |   stoi(const string& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~
/usr/include/c++/14/bits/basic_string.h:4164:22: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'const std::string&' {aka 'const std::__cxx11::basic_string<char>&'}
 4164 |   stoi(const string& __str, size_t* __idx = 0, int __base = 10)
      |        ~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:4432:3: note: candidate: 'int std::__cxx11::stoi(const std::wstring&, std::size_t*, int)'
 4432 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~
/usr/include/c++/14/bits/basic_string.h:4432:23: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'const std::wstring&' {aka 'const std::__cxx11::basic_string<wchar_t>&'}
 4432 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |        ~~~~~~~~~~~~~~~^~~~~
a.cc:21:39: error: invalid type argument of unary '*' (have 'int')
   21 |       num += (stoi(s.at(n-i-1)) * 10 ** i) % p;
      |                                       ^~~
a.cc:23:17: error: missing template arguments before '[' token
   23 |       ans += map[num];
      |                 ^
a.cc:27:16: error: expected initializer before '+=' token
   27 |       map[num] += 1;
      |                ^~
a.cc:27:16: error: expected ';' before '+=' token