Language: C++

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

ll M;

template <typename T>
class Matrix {
public:
  vector<vector<T>> mat;
  Matrix(int h, int w) : mat(h, vector<T>(w)) {}
  vector<T>& operator[](int i) { return mat[i]; }
  const vector<T>& operator[](int i) const { return mat[i]; }
  const size_t height() const { return mat.size(); }
  const size_t width() const { return mat[0].size(); }

  // only square matrix
  static Matrix identity(int n) {
    Matrix E(n, n);
    for (int i = 0; i < n; ++i) E[i][i] = 1;
    return E;
  }

  // O(N^3)
  Matrix& operator*=(const Matrix& m) {
    int h = m.height(), w = m.width();
    vector<vector<T>> res(height(), vector<T>(w));
    for (int i = 0; i < height(); ++i)
      for (int k = 0; k < h; ++k)
        for (int j = 0; j < w; ++j) {
          if (i == 0)
            (res[i][j] += (*this)[i][k] % M * (m[k][j] % M)) %= M;
          else
            res[i][j] += (*this)[i][k] * m[k][j];
        }
    mat.swap(res);
    return *this;
  }

  Matrix& operator*(const Matrix& rhs) { return Matrix(*this) *= rhs; }

  // O(N^3logK)
  Matrix operator^(T exponent) {
    Matrix res = Matrix::identity(height());
    Matrix product = *this;

    while (exponent) {
      if (exponent & 1) res *= product;
      product *= product;
      exponent >>= 1;
    }
    return res;
  }

  friend ostream& operator<<(ostream& os, Matrix& m) {
    os << "---- Matrix ----" << endl;
    for (int i = 0; i < m.height(); ++i)
      for (int j = 0; j < m.width(); ++j)
        os << m[i][j] << " \n"[j == m.width() - 1];
    os << "---- Matrix end ----" << endl;
    return os;
  }
};

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  ll L, A, B;
  cin >> L >> A >> B >> M;
  ll now = A;
  ll ten = 1;

  // 10^d 1 0   ans
  // 0    1 1   now
  // 0    0 1   b
  ll ans = 0;
  for (int i = 0; i < 18 && L > 0; ++i) {
    ten *= 10;
    ll l = max((ll)0, (ten - now + B - 1) / B);
    ll x = min(L, max(0ll, l));

    Matrix<ll> b(3, 3);
    Matrix<ll> c(3, 1);
    b[0][0] = ten % M;
    b[0][1] = 1;
    b[1][1] = 1;
    b[1][2] = 1;
    b[2][2] = 1;
    b = b ^ x;
    c[0][0] = ans;
    c[1][0] = now;
    c[2][0] = B;
    b *= c;
    ans = b[0][0];
    now = b[1][0];
    L -= x;
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:92:22: error: no matching function for call to 'max(long long int, ll&)'
   92 |     ll x = min(L, max(0ll, l));
      |                   ~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:92:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'll' {aka 'long int'})
   92 |     ll x = min(L, max(0ll, l));
      |                   ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:92:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   92 |     ll x = min(L, max(0ll, l));
      |                   ~~~^~~~~~~~