Language: C++

#include <bits/stdc++.h>
using namespace std;
long long MOD;
unsigned long long modpow(unsigned long long b){
  unsigned long long ans = 1;
  long long a = 10;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return ans;
}
unsigned long long gp(int i, unsigned long long N){
  //1+10^i+10^2i+...+10^(N-1)i
  if (N == 1){
    return 1;
  } else {
    if (N % 2 == 0){
      unsigned long long ans = gp(i, N / 2);
      ans *= modpow(N / 2 * i) + 1;
      ans %= MOD;
      return ans;
    } else {
      unsigned long long ans = gp(i, N - 1);
      for (int j = 0; j < i; j++){
        ans *= 10;
        ans %= MOD;
      }
      ans++;
      ans %= MOD;
      return ans;
    }
  }
}
unsigned long long apgp(int i, unsigned long long N){
  //N+(N-1)*10^i+(N-2)*10^2i+...+1*10^(N-1)i
  if (N == 1){
    return 1;
  } else {
    if (N % 2 == 0){
      unsigned long long ans = apgp(i, N / 2);
      ans *= modpow(N / 2 * i) + 1;
      ans %= MOD;
      ans += gp(i, N / 2) * (N / 2 % MOD) % MOD;
      ans %= MOD;
      return ans;
    } else {
      unsigned long long ans = apgp(i, N - 1);
      for (int j = 0; j < i; j++){
        ans *= 10;
        ans %= MOD;
      }
      ans += N;
      ans %= MOD;
      return ans;
    }
  }
}
long long apgp2(unsigned long long lb, unsigned long long ub, unsigned long long B, int i){
  unsigned long long len = (ub - lb) / B + 1;
  unsigned long long ans = 0;
  if (lb > B){
    ans += gp(i, len) % MOD * ((lb - B) % MOD) % MOD;
  } else {
    ans -= gp(i, len) % MOD * ((B - lb) % MOD) % MOD;
    ans += MOD;
  }
  ans %= MOD;
  ans += (B % MOD) * apgp(i, len) % MOD;
  ans %= MOD;
  return ans;
}
int main(){
  long long L, A, B, M;
  cin >> L >> A >> B >> M;
  MOD = M;
  unsigned long long C = A + B * (L - 1);
  long long r = A % B;
  long long ans = 0;
  unsigned long long digit_cnt = 0;
  for (int i = 18; i >= 1; i--){
    long long lb = 1;
    for (int j = 0; j < i - 1; j++){
      lb *= 10;
    }
    long long ub = lb * 10;
    lb = (lb - r + B - 1) / B * B + r;
    ub = (ub - r - 1) / B * B + r;
    if (lb <= C && A <= ub && lb <= ub){
      lb = max(lb, A);
      ub = min(ub, C);
      ans += apgp2(lb, ub, B, i) * modpow(digit_cnt) % MOD;
      digit_cnt += i * ((ub - lb) / B + 1);
    }
  }
  ans %= MOD;
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:96:15: error: no matching function for call to 'min(long long int&, long long unsigned int&)'
   96 |       ub = min(ub, C);
      |            ~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:96:15: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   96 |       ub = min(ub, C);
      |            ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:96:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   96 |       ub = min(ub, C);
      |            ~~~^~~~~~~