Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 998244353;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

struct UnionFind {
    vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(
        int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {  // xとyの木を併合
        int rx = root(x);       // xの根をrx
        int ry = root(y);       // yの根をry
        if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] =
            ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

ll ans = 0;

int main() {
    ll n, x, m;
    cin >> n >> x >> m;
    x %= m;

    vector<bool> check(100010, false);

    ll zero = x;
    vector<ll> amari;

    amari.push_back(x);
    check[x] = true;

    ll key = 0;
    while (1) {
        x = x * x;
        x %= m;

        zero += x;
        if (check[x] == true) {
            key = x;
            break;
        }
        if (x == 0) {
            cout << zero << "\n";
            return 0;
        }

        check[x] = true;
        amari.push_back(x);
    }

    ll sum = 0, keynum = 0;
    bool yes = false;
    vector<ll> BI;
    rep(i, amari.size()) {
        if (key == amari[i]) {
            yes = true;
            keynum = i;
        }

        if (yes == false) {
            ans += amari[i];
        } else {
            sum += amari[i];
            BI.push_back(amari[i]);
        }
    }

    ans += (n / (amari.size() - keynum)) * sum;
    rep(i, max(0ll, n % (BI.size()) - 2)) { ans += BI[i]; }

    cout << ans << "\n";
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:109:15: error: no matching function for call to 'max(long long int, long long unsigned int)'
  109 |     rep(i, max(0ll, n % (BI.size()) - 2)) { ans += BI[i]; }
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:4:38: note: in definition of macro 'rep'
    4 | #define rep(i, n) for (ll i = 0; i < n; ++i)
      |                                      ^
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: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:109:15: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
  109 |     rep(i, max(0ll, n % (BI.size()) - 2)) { ans += BI[i]; }
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:4:38: note: in definition of macro 'rep'
    4 | #define rep(i, n) for (ll i = 0; i < n; ++i)
      |                                      ^
/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:109:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  109 |     rep(i, max(0ll, n % (BI.size()) - 2)) { ans += BI[i]; }
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:4:38: note: in definition of macro 'rep'
    4 | #define rep(i, n) for (ll i = 0; i < n; ++i)
      |                                      ^