Language: C++

#include <bits/stdc++.h>

using namespace std;

long long m, s, ans = 1e12;

long long f(long long b, long long n){
    if(b == 1) return 0;
    if(n < b) return n;
    else return f(b, n / b) + n % b;
}

int main(){
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> m >> s;
    if(m == s){
        cout << m + 1;
        return 0;
    }
    for(int i = 2; i*i <= n; i++){
        if(f(i, m) == s)
            ans = min (ans,i);
    }
    for(int i = 2; i*i <= s; i++){
        if(f(i, m) == s)
            ans = min (ans,i);
    }
    if(m > s){
        for(int i = 2; i*i <= m - s; i++){
            int pointer = (m - s)/i + 1;
            if(f(i, m) == s)
                ans = min(ans,i);
            if(f(pointer, m) == s)
                ans = min(ans,pointer);
        }
    }
    if(ans!=1e12) {cout << ans; exit(0);}
    cout << "-1\n";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:27: error: 'n' was not declared in this scope
   20 |     for(int i = 2; i*i <= n; i++){
      |                           ^
a.cc:22:23: error: no matching function for call to 'min(long long int&, int&)'
   22 |             ans = min (ans,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: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:22:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   22 |             ans = min (ans,i);
      |                   ~~~~^~~~~~~
/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:22:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   22 |             ans = min (ans,i);
      |                   ~~~~^~~~~~~
a.cc:26:23: error: no matching function for call to 'min(long long int&, int&)'
   26 |             ans = min (ans,i);
      |                   ~~~~^~~~~~~
/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:26:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   26 |             ans = min (ans,i);
      |                   ~~~~^~~~~~~
/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
/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:26:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   26 |             ans = min (ans,i);
      |                   ~~~~^~~~~~~
a.cc:32:26: error: no matching function for call to 'min(long long int&, int&)'
   32 |                 ans = min(ans,i);
      |                       ~~~^~~~~~~
/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:32:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   32 |                 ans = min(ans,i);
      |                       ~~~^~~~~~~
/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
/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:32:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |                 ans = min(ans,i);
      |                       ~~~^~~~~~~
a.cc:34:26: error: no matching function for call to 'min(long long int&, int&)'
   34 |                 ans = min(ans,pointer);
      |                       ~~~^~~~~~~~~~~~~
/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:34:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |                 ans = min(ans,pointer);
      |                       ~~~^~~~~~~~~~~~~
/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
/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:34:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |                 ans = min(ans,pointer);
      |                       ~~~^~~~~~~~~~~~~