Language: C++

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint n, s;
	cin >> n >> s;

	auto check = [&](lint &b) {
		if (b < 2) return false;
		lint tmp = n, sum = 0;
		while (tmp) {
			sum += tmp % b;
			tmp /= b;
		}
		return sum == s;
	};

	auto end = [&](lint &b) {
		cout << b << "\n";
		exit(0);
	};

	if (n < s) end(-1);
	else if (n == s) end(n + 1);

	for (int i = 2; i < 320000; i++) if (check(i)) end(i);
	for (int i = 320000; i >= 1; i--) {
		lint b = (n - s) / i + 1;
		if (check(b)) end(b);
	}

	end(-1);

}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:23: error: no match for call to '(main()::<lambda(lint&)>) (int)'
   61 |         if (n < s) end(-1);
      |                    ~~~^~~~
a.cc:56:20: note: candidate: 'main()::<lambda(lint&)>' (near match)
   56 |         auto end = [&](lint &b) {
      |                    ^
a.cc:56:20: note:   conversion of argument 1 would be ill-formed:
a.cc:61:24: error: cannot bind non-const lvalue reference of type 'lint&' {aka 'long long int&'} to a value of type 'int'
   61 |         if (n < s) end(-1);
      |                        ^~
a.cc:62:29: error: no match for call to '(main()::<lambda(lint&)>) (lint)'
   62 |         else if (n == s) end(n + 1);
      |                          ~~~^~~~~~~
a.cc:56:20: note: candidate: 'main()::<lambda(lint&)>' (near match)
   56 |         auto end = [&](lint &b) {
      |                    ^
a.cc:56:20: note:   conversion of argument 1 would be ill-formed:
a.cc:62:32: error: cannot bind non-const lvalue reference of type 'lint&' {aka 'long long int&'} to an rvalue of type 'lint' {aka 'long long int'}
   62 |         else if (n == s) end(n + 1);
      |                              ~~^~~
a.cc:64:51: error: no match for call to '(main()::<lambda(lint&)>) (int&)'
   64 |         for (int i = 2; i < 320000; i++) if (check(i)) end(i);
      |                                              ~~~~~^~~
a.cc:46:22: note: candidate: 'main()::<lambda(lint&)>' (near match)
   46 |         auto check = [&](lint &b) {
      |                      ^
a.cc:46:22: note:   conversion of argument 1 would be ill-formed:
a.cc:64:52: error: cannot bind non-const lvalue reference of type 'lint&' {aka 'long long int&'} to a value of type 'int'
   64 |         for (int i = 2; i < 320000; i++) if (check(i)) end(i);
      |                                                    ^
a.cc:64:59: error: no match for call to '(main()::<lambda(lint&)>) (int&)'
   64 |         for (int i = 2; i < 320000; i++) if (check(i)) end(i);
      |                                                        ~~~^~~
a.cc:56:20: note: candidate: 'main()::<lambda(lint&)>' (near match)
   56 |         auto end = [&](lint &b) {
      |                    ^
a.cc:56:20: note:   conversion of argument 1 would be ill-formed:
a.cc:64:60: error: cannot bind non-const lvalue reference of type 'lint&' {aka 'long long int&'} to a value of type 'int'
   64 |         for (int i = 2; i < 320000; i++) if (check(i)) end(i);
      |                                                            ^
a.cc:70:12: error: no match for call to '(main()::<lambda(lint&)>) (int)'
   70 |         end(-1);
      |         ~~~^~~~
a.cc:56:20: note: candidate: 'main()::<lambda(lint&)>' (near match)
   56 |         auto end = [&](lint &b) {
      |                    ^
a.cc:56:20: note:   conversion of argument 1 would be ill-formed:
a.cc:70:13: error: cannot bind non-const lvalue reference of type 'lint&' {aka 'long long int&'} to a value of type 'int'
   70 |         end(-1);
      |             ^~