Language: C++

#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
//#define MOD 1000000007
 
ll n,k,x,y,L,A,B,M,MOD;
 


class modint {
public:
  long long value;

  //+
	const modint operator + (modint mtmp) const{
    modint mdnt;
    mdnt.value=(this->value+mtmp.value);
    if (mdnt.value>=MOD)mdnt.value-=MOD;
    return mdnt;
	}
	const modint operator + (long long ltmp) const{
    modint mdnt;
    long long tmp=ltmp%MOD;
    if (tmp<0)tmp+=MOD;
    mdnt.value=(this->value+tmp);
    if (mdnt.value>=MOD)mdnt.value-=MOD;
    return mdnt;
	}

  //-
	const modint operator - (modint mtmp) const{
    modint mdnt;
    mdnt.value=(this->value-mtmp.value+MOD);
    if (mdnt.value>=MOD)mdnt.value-=MOD;
    return mdnt;
	}
	const modint operator - (long long ltmp) const{
    modint mdnt;
    long long tmp=ltmp%MOD;
    if (tmp<0)tmp+=MOD;
    mdnt.value=(this->value-tmp+MOD);
    if (mdnt.value>=MOD)mdnt.value-=MOD;
    return mdnt;
	}

  //*
	const modint operator * (modint mtmp) const{
    modint mdnt;
    mdnt.value=(this->value*mtmp.value)%MOD;
    return mdnt;
	}
	const modint operator * (long long ltmp) const{
    modint mdnt;
    long long ltmpm=ltmp%MOD;
    if (ltmpm<0)ltmpm+=MOD;
    mdnt.value=(this->value*ltmpm)%MOD;
    return mdnt;
	}

  ///
	const modint operator / (long long ltmp) const{
    modint mdnt;
    long long ltmpm=ltmp%MOD;
    if (ltmpm<0)ltmpm+=MOD;
    long long mdnv=this->value;

    long long x0=MOD,x1=ltmpm,x2,n0=0LL,n1=1LL,n2,t=mdnv%ltmpm,m,ans;
    if (t==0){
      mdnt.value=mdnv/ltmpm;
      return mdnt;
    } 
      for(int i=0;i<900;i++){
        m=x0/x1;
        x2=x0-x1*m;
        n2=(n0-m*n1)%MOD;
        if (x2==1){
          ans=(n2+MOD)%MOD;
          break;
        }
        x0=x1;x1=x2;
        n0=n1;n1=n2;
      }

    mdnt.value=(mdnv+((t*ans)%MOD)*ltmpm-t)/ltmpm;
    return mdnt;
  }
	const modint operator / (modint mtmp) const{
    modint mdnt;
    //mdnt.value=this->value;
    return (*this)/mtmp.value;
	}
  
  //%
	const modint operator % (long long ltmp) const{
    modint mdnt;
    mdnt.value=(this->value%ltmp);
    return mdnt;
	}


  //代入演算子のオーバーロード
  modint &operator = (const modint mtmp) 
  {
      this->value = mtmp.value;
      return *this;
  }
  modint &operator = (const long long ltmp) 
  {
      this->value = ltmp%MOD;
      if ((this->value)<0)this->value+=MOD;
      return *this;
  }
  
  //+=
  modint &operator += (const modint mtmp) 
  {
      this->value = (this->value+mtmp.value);
      if (this->value>=MOD)this->value-=MOD;
      return *this;
  }
  modint &operator += (long long ltmp) 
  {
      long long tmp=ltmp%MOD;
      if (tmp<0)tmp+=MOD;
      this->value=(this->value+tmp);
      if (this->value>=MOD)this->value-=MOD;
      return *this;
  }

  //-=
  modint &operator -= (const modint mtmp) 
  {
      this->value = (this->value-mtmp.value+MOD);
      if (this->value>=MOD)this->value-=MOD;
      return *this;
  }
  modint &operator -= (long long ltmp) 
  {
      long long tmp=ltmp%MOD;
      if (tmp<0)tmp+=MOD;
      this->value=(this->value-tmp+MOD);
      if (this->value>=MOD)this->value-=MOD;
      return *this;
  }
  //*=
  modint &operator *= (const modint mtmp) 
  {
      this->value = this->value*mtmp.value%MOD;
      return *this;
  }
  modint &operator *= (long long ltmp) 
  {
      this->value = this->value*(ltmp%MOD)%MOD;
      if (this->value<0)this->value+=MOD;
      return *this;
  }  
  ///=
  modint &operator /= (const modint mtmp) 
  {
      modint tmp=(*this)/mtmp.value;
      this->value = tmp.value;
      return *this;
  }
  modint &operator /= (long long ltmp) 
  {
      modint tmp=(*this)/ltmp;
      this->value = tmp.value;
      return *this;
  }
  //%=
  modint &operator %= (long long ltmp) 
  {
      this->value%=ltmp;
      return *this;
  }


  //exp関数
  //aのn乗 mod c
  modint exp(long long n){
    long long ans=1LL,aa=this->value,beki=n;
    for(int i=0;i<64;i++){
      if (beki%2==1) ans=ans*aa%MOD;
      aa=aa*aa%MOD;
      beki/=2;
      if (beki==0)break;
    }
    modint mdnt;
    mdnt.value=ans;
    return mdnt;
  }
  //friend ostream& operator << (ostream& os, const modint& m);
};

ostream& operator << (ostream& os, const modint& m)
{
  os << m.value;
  return os;
}
 
using vi = vector<modint>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
 
ll mylog10(unsigned long long a){
	unsigned long long w=1ULL;
	for(;w<=a;w*=10ULL){
	}
	return (ll)(w/10ULL);
}
 
void matmul(vvi &C,vvi A,vvi B)
{
	REP(i,k){	
		REP(j,k){	
			C[i][j]=0;
			REP(l,k){
				C[i][j]+=A[l][j]*B[i][l];
			}
		}
	}
}
 
void matpow(vvi &matans,vvi &imat,ll num){
  vvi updmat(k, vi(k));  // k * k の正方行列
  REP(i,k) matans[i][i]=1;//単位行列 I
  REP(i,k)REP(j,k)updmat[i][j]=imat[i][j];
	while(num)
	{
		if (num%2==1)
		{
			matmul(matans,matans,updmat);
		}
		num/=2;
		matmul(updmat,updmat,updmat);
	}
	return;
}
 
 
int main(){
  cin >> L >> A >> B>>M;
  MOD=M;
  modint ans;
  ans=0;
  ll lasts;
  k=3;
  vvi mat2d(k, vi(k));  // k * k の正方行列
  mat2d[0][0]=1;
  mat2d[2][0]=0;
  mat2d[0][0]=1;
  modint e,sm;
  sm=1;
	for (int i=0;i<999;i++){
		lasts=(L-1)*B+A;
		ll lowL=(mylog10(lasts)-1-A)/B;
		if ((mylog10(lasts)-1-A)<0)
		{
			lowL=-1;
		}
		ll Lnmu=L-1-lowL;
		mat2d[1][1]=mat2d[2][2]=mat2d[1][0]=(mylog10(lasts)*10LL);
		mat2d[2][1]=-B%M*mat2d[1][1];
    vvi ansmat(k, vi(k));  // k * k の正方行列
		matpow(ansmat,mat2d,Lnmu-1);
		modint pans;
		pans=(ansmat[0][0]*(lasts)+ansmat[1][0]*(lasts-B)+ansmat[2][0]);
		ans=ans+pans*sm;
		e=(mylog10(lasts)%M*10LL);
		sm=sm*e.exp(Lnmu);
		L=lowL+1;
		if (L==0)break;
	}
  cout<<ans<<endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:263:33: error: no match for 'operator*' (operand types are 'long long int' and '__gnu_cxx::__alloc_traits<std::allocator<modint>, modint>::value_type' {aka 'modint'})
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/complex:400:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const complex<_Tp>&)'
  400 |     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:400:5: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   mismatched types 'const std::complex<_Tp>' and 'long long int'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
/usr/include/c++/14/complex:409:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const _Tp&)'
  409 |     operator*(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:409:5: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   mismatched types 'const std::complex<_Tp>' and 'long long int'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
/usr/include/c++/14/complex:418:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const complex<_Tp>&)'
  418 |     operator*(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:418:5: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   '__gnu_cxx::__alloc_traits<std::allocator<modint>, modint>::value_type' {aka 'modint'} is not derived from 'const std::complex<_Tp>'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long long int'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long long int'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   '__gnu_cxx::__alloc_traits<std::allocator<modint>, modint>::value_type' {aka 'modint'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long long int'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   '__gnu_cxx::__alloc_traits<std::allocator<modint>, modint>::value_type' {aka 'modint'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const valarray<_Tp>&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   mismatched types 'const std::valarray<_Tp>' and 'long long int'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   mismatched types 'const std::valarray<_Tp>' and 'long long int'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   template argument deduction/substitution failed:
a.cc:263:44: note:   '__gnu_cxx::__alloc_traits<std::allocator<modint>, modint>::value_type' {aka 'modint'} is not derived from 'const std::valarray<_Tp>'
  263 |                 mat2d[2][1]=-B%M*mat2d[1][1];
      |                                            ^