Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <limits.h>
#include <string.h>
using namespace std;
typedef unsigned long long int ll;

typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vii;


#define F first
#define S second

#define ERR 1e-9
#define MAXN 100010

#ifndef ONLINE_JUDGE
    #define var(x) cerr << #x << ": " << x;
#else
    #define var(x)
#endif // ONLINE_JUDGE

void aggMax(ll & res, ll x){ if(x > res)res = x; }
void aggMin(ll & res, ll x){ if(x < res)res = x; }

ll II(){ ll i; cin >> i; return i; }
void OI(ll i){ cout << i; }

ll isRes(ll N, ll M, ll x){
    ll resParz = x * (N-1);
    if(M - resParz > 0)return ((M-resParz)%x == 0)?1:0;
    else return -1;
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE*/

    ll N = II(), M = II(), res = 0;
    if(N > M){ cout << 0; return 0; }
    for(ll i=1; i<=M; i++){
        if(M%i == 0){
            ll r = isRes(N, M, i);
            if(r == 1)aggMax(res, i);
            else if(r == -1)break;
        }
    }
    cout << res;
    return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <limits.h>
#include <string.h>
using namespace std;
typedef unsigned long long int ll;

typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vii;


#define F first
#define S second

#define ERR 1e-9
#define MAXN 100010

#ifndef ONLINE_JUDGE
    #define var(x) cerr << #x << ": " << x;
#else
    #define var(x)
#endif // ONLINE_JUDGE

void aggMax(ll & res, ll x){ if(x > res)res = x; }
void aggMin(ll & res, ll x){ if(x < res)res = x; }

ll II(){ ll i; cin >> i; return i; }
void OI(ll i){ cout << i; }

ll isRes(ll N, ll M, ll x){
    ll resParz = x * (N-1);
    if(M - resParz > 0)return ((M-resParz)%x == 0)?1:0;
    else return -1;
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE*/

    ll N = II(), M = II(), res = 0;
    if(N > M){ cout << 0; return 0; }
    for(ll i=1; i<=M; i++){
        if(M%i == 0){
            ll r = isRes(N, M, i);
            if(r == 1)aggMax(res, i);
            else if(r == -1)break;
        }
    }
    cout << res;
    return 0;
}


Compiler output:
a.cc:85:6: error: redefinition of 'void aggMax(ll&, ll)'
   85 | void aggMax(ll & res, ll x){ if(x > res)res = x; }
      |      ^~~~~~
a.cc:28:6: note: 'void aggMax(ll&, ll)' previously defined here
   28 | void aggMax(ll & res, ll x){ if(x > res)res = x; }
      |      ^~~~~~
a.cc:86:6: error: redefinition of 'void aggMin(ll&, ll)'
   86 | void aggMin(ll & res, ll x){ if(x < res)res = x; }
      |      ^~~~~~
a.cc:29:6: note: 'void aggMin(ll&, ll)' previously defined here
   29 | void aggMin(ll & res, ll x){ if(x < res)res = x; }
      |      ^~~~~~
a.cc:88:4: error: redefinition of 'll II()'
   88 | ll II(){ ll i; cin >> i; return i; }
      |    ^~
a.cc:31:4: note: 'll II()' previously defined here
   31 | ll II(){ ll i; cin >> i; return i; }
      |    ^~
a.cc:89:6: error: redefinition of 'void OI(ll)'
   89 | void OI(ll i){ cout << i; }
      |      ^~
a.cc:32:6: note: 'void OI(ll)' previously defined here
   32 | void OI(ll i){ cout << i; }
      |      ^~
a.cc:91:4: error: redefinition of 'll isRes(ll, ll, ll)'
   91 | ll isRes(ll N, ll M, ll x){
      |    ^~~~~
a.cc:34:4: note: 'll isRes(ll, ll, ll)' previously defined here
   34 | ll isRes(ll N, ll M, ll x){
      |    ^~~~~
a.cc:97:5: error: redefinition of 'int main()'
   97 | int main(){
      |     ^~~~
a.cc:40:5: note: 'int main()' previously defined here
   40 | int main(){
      |     ^~~~