Language: C++

/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

int n , s ;

int f ( int n , int b ) {
	if ( b == 1 )
		return 4e18 ; 
	int ret = 0 ;
	while ( n ) {
		ret += ( n % b ) ;
		n /= b ; 
	}
	return ret ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> s ;
	int res = 4e18 ; 
	for ( int i = 2 ; i <= 2e6 ; ++ i )
		if ( f ( n , i ) == s )
			smin ( res , i ) ; 
	if ( s == 1 )
		return cout << n << '\n' , 0 ;
	if ( s == n )
		return cout << s + 1 << '\n' , 0 ;
	if ( s > n )
		return cout << -1 << '\n' , 0 ; 
	int t = n - s ;
	for ( int possible = 1 ; possible <= min ( 1LL * 2e6 , t ) ; ++ possible ) {
		if ( t % possible == 0 ) {
			if ( f ( n , possible + 1 ) == s )
				smin ( res , possible + 1 ) ;
			if ( f ( n , ( t / possible ) + 1 ) == s )
				smin ( res , ( t / possible ) + 1 ) ; 
		}
	}
	if ( res == 4e18 ) res = -1 ;
	cout << res << '\n' ; 
}


Compiler output:
a.cc: In function 'int32_t main()':
a.cc:43:50: error: no matching function for call to 'min(double, long long int&)'
   43 |         for ( int possible = 1 ; possible <= min ( 1LL * 2e6 , t ) ; ++ possible ) {
      |                                              ~~~~^~~~~~~~~~~~~~~~~
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:2:
/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:43:50: note:   deduced conflicting types for parameter 'const _Tp' ('double' and 'long long int')
   43 |         for ( int possible = 1 ; possible <= min ( 1LL * 2e6 , t ) ; ++ possible ) {
      |                                              ~~~~^~~~~~~~~~~~~~~~~
/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:43:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'double'
   43 |         for ( int possible = 1 ; possible <= min ( 1LL * 2e6 , t ) ; ++ possible ) {
      |                                              ~~~~^~~~~~~~~~~~~~~~~