Language: C++

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 20;
long long GCD(long long a, long long b)
{
    return (b == 0) ? a : GCD(b, a % b);
}
inline long long LCM(long long a, long long b)
{
    return a / GCD(a, b) * b;
}
inline long long normalize(long long x, long long mod)
{
    x %= mod;
    if (x < 0)
        x += mod;
    return x;
}
struct GCD_type
{
    long long x, y, d;
};
GCD_type ex_GCD(long long a, long long b)
{
    if (b == 0)
        return {1, 0, a};
    GCD_type pom = ex_GCD(b, a % b);
    return {pom.y, pom.x - a / b * pom.y, pom.d};
}
ll testCases;
ll t;
long long a[N], n[N], ans, lcm;

ll crt(ll a1,ll n1,ll a2,ll n2)
{
    t=2;
    a[1]=a1;
    a[2]=a2;
    n[1]=n1;
    n[2]=n2;

    for(ll i=1; i<=t; i++)
    {
        normalize(a[i], n[i]);
    }
    ans = a[1];
    lcm = n[1];
    for(ll i = 2; i <= t; i++)
    {
        auto pom = ex_GCD(lcm, n[i]);
        ll x1 = pom.x;
        ll d = pom.d;
        if((a[i] - ans) % d != 0)
            return -1;
        ans = normalize(ans + x1 * (a[i] - ans) / d % (n[i] / d) * lcm, lcm * n[i] / d);
        lcm = LCM(lcm, n[i]); // you can save time by replacing above lcm * n[i] /d by lcm = lcm * n[i] / d
    }
    return ans;
}
ll sum(ll n)
{
    return n*(n+1)/2;
}
ll nn;
main()
{
    ll n;
    cin>>n;
    ll ans=LLONG_MAX;
    for(ll k=1; k<=100; k++)
    {
        if(sum(k)%n==0)
        {
            ans=min(ans,k);
        }
    }

    nn=n;
    vector<ll>div;
    for(ll i=2; i*i<=n; i++)
    {
        if(n%i!=0)
            continue;
        ll now=1;
        while(n%i==0)
        {
            now*=i;
            n/=i;
        }
        div.push_back(now);
    }


    if(n!=1)
        div.push_back(n);
//    cout<<"paisi"<<endl;
//    cout<<div.size() <<endl;

    ll p=div.size();
    n=nn;
    for(ll mask=0; mask<(1<<p); mask++)
    {
        ll a=1,b=1;
        for(ll j=0; j<p; j++)
        {
            if(mask&(1<<j))
            {
                a*=div[j];
            }
        }
        //   cout<<"M "<<a<<endl;
        b=n/a;

        ll k=crt(1,a,0,b);
        //   cout<<a<<' '<<b<<' '<<k<<endl;
        if(k>=2&&sum(k-1)%n==0)
        {
            ans=min(ans,k-1);
        }

        k=crt(1,a*2,0,b);
        // cout<<a*2<<' '<<b<<' '<<k<<endl;

        if(k>=2&&sum(k-1)%n==0)
        {
            ans=min(ans,k-1);
        }

        k=crt(1,a,0,b*2);
        // cout<<a<<' '<<b*2<<' '<<k<<endl;

        if(k>=2&&sum(k-1)%n==0)
        {
            ans=min(ans,k-1);
        }
    }
    cout<<ans;

}


Compiler output:
a.cc: In function 'long long int crt(long long int, long long int, long long int, long long int)':
a.cc:48:5: error: reference to 'lcm' is ambiguous
   48 |     lcm = n[1];
      |     ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:58,
                 from a.cc:1:
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:33:28: note:                 'long long int lcm'
   33 | long long a[N], n[N], ans, lcm;
      |                            ^~~
a.cc:51:27: error: reference to 'lcm' is ambiguous
   51 |         auto pom = ex_GCD(lcm, n[i]);
      |                           ^~~
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:33:28: note:                 'long long int lcm'
   33 | long long a[N], n[N], ans, lcm;
      |                            ^~~
a.cc:56:68: error: reference to 'lcm' is ambiguous
   56 |         ans = normalize(ans + x1 * (a[i] - ans) / d % (n[i] / d) * lcm, lcm * n[i] / d);
      |                                                                    ^~~
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:33:28: note:                 'long long int lcm'
   33 | long long a[N], n[N], ans, lcm;
      |                            ^~~
a.cc:56:73: error: reference to 'lcm' is ambiguous
   56 |         ans = normalize(ans + x1 * (a[i] - ans) / d % (n[i] / d) * lcm, lcm * n[i] / d);
      |                                                                         ^~~
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:33:28: note:                 'long long int lcm'
   33 | long long a[N], n[N], ans, lcm;
      |                            ^~~
a.cc:57:9: error: reference to 'lcm' is ambiguous
   57 |         lcm = LCM(lcm, n[i]); // you can save time by replacing above lcm * n[i] /d by lcm = lcm * n[i] / d
      |         ^~~
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:33:28: note:                 'long long int lcm'
   33 | long long a[N], n[N], ans, lcm;
      |                            ^~~
a.cc:57:19: error: reference to 'lcm' is ambiguous
   57 |         lcm = LCM(lcm, n[i]); // you can save time by replacing above lcm * n[i] /d by lcm = lcm * n[i] / d
      |                   ^~~
/usr/include/c++/14/numeric:188:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::lcm(_Mn, _Nn)'
  188 |     lcm(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:33:28: note:                 'long long int lcm'
   33 | long long a[N], n[N], ans, lcm;
      |                            ^~~
a.cc: At global scope:
a.cc:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main()
      | ^~~~