/* * if you are interested in the reference code here, * see https://g...content-available-to-author-only...b.com/georeth/OJLIBS for more information * * Solution Author : Georeth Chow <georeth2010@gmail.com> */ #include <cstdio> #include <cmath> #include <cstring> // memset #include <cstdlib> // malloc #include <cstdint> // int64_t #include <cinttypes> // PRId64 SCNd64 #include <numeric> // accumulate, partial_sum, inner_product, iota, adjacent_difference #include <vector> #include <map> #include <set> #include <tuple> // pair, tuple #include <iostream> #include <algorithm> #include <utility> #include <iterator> template <typename It> struct iter_range : std::pair<It, It> { typedef std::pair<It, It> base_t; using base_t::base_t; It begin() { return base_t::first; } It end() { return base_t::second; } }; template <typename It> iter_range<std::reverse_iterator<It>> rev(const iter_range<It> &origin) { using rev_t = std::reverse_iterator<It>; return {rev_t(origin.second), rev_t(origin.first)}; } template <typename Int = int> struct int_iter { Int i; explicit int_iter(Int i = 0) : i(i) { } Int operator*() const { return i; } int_iter &operator++() { ++i; return *this; } int_iter &operator--() { --i; return *this; } int_iter operator+(Int step) const { return int_iter(i + step); } int_iter operator-(Int step) const { return int_iter(i - step); } Int operator-(const int_iter &that) const { return i - that.i; } int_iter &operator+=(Int step) { i += step; return *this; } int_iter &operator-=(Int step) { i -= step; return *this; } bool operator==(const int_iter &that) const { return i == that.i; } bool operator!=(const int_iter &that) const { return !(*this == that); } Int operator[](Int n) { return i + n; } typedef Int difference_type; typedef Int value_type; typedef Int *pointer; typedef Int reference; // not a int container, never reference to int typedef std::random_access_iterator_tag iterator_category; }; typedef iter_range<int_iter<>> range_t; range_t range(int b, int e) { return {int_iter<>(b), int_iter<>(e > b ? e : b)}; } range_t range(int n) { return range(0, n); } range_t nrange(int n) { return range(1, n+1); } range_t inrange(int b, int e) { return range(b, e + 1); } using namespace std; // use as solution header. name polution is fine. #ifdef LOCAL_JUDGE # define pr_debug(...) fprintf(stderr, __VA_ARGS__) #else # define pr_debug(...) #endif template <typename T> bool chmax(T &m, const T &v) { if (v > m) return m = v, true; return false; } template <typename T> bool chmin(T &m, const T &v) { if (v < m) return m = v, true; return false; } void fio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } #include <boost/multiprecision/gmp.hpp> using namespace boost::multiprecision; /* ===== SOLUTION START ===== */ typedef int_iter<int64_t> ll_it; int64_t N; int64_t ValidB; mpz_int all_ones(int nd, int64_t B) { mpz_int p(1); mpz_int ans = 0; while (nd--) { ans += p; p *= B; } return ans; } void valid_digit(int nd) { lower_bound(ll_it(2LL), ll_it(numeric_limits<int64_t>::max()), N, [=](int64_t B, int64_t N) { mpz_int num = all_ones(nd, B); if (num == N) chmin(ValidB, B); return all_ones(nd, B) < N; }); } void solve() { cin >> N; ValidB = N - 1; for (int i : nrange(64)) valid_digit(i); cout << ValidB << endl; } int main() { int T; cin >> T; for (int i : nrange(T)) { cout << "Case #" << i << ": "; solve(); } return 0; }
Standard input is empty
/home/9Y3VA6/ccCRpjg7.o: In function `all_ones(int, long long)': prog.cpp:(.text+0xdd): undefined reference to `__gmpz_init' prog.cpp:(.text+0xf9): undefined reference to `__gmpz_set_si' prog.cpp:(.text+0x102): undefined reference to `__gmpz_init' prog.cpp:(.text+0x120): undefined reference to `__gmpz_set_si' prog.cpp:(.text+0x16e): undefined reference to `__gmpz_add' prog.cpp:(.text+0x179): undefined reference to `__gmpz_init' prog.cpp:(.text+0x1c9): undefined reference to `__gmpz_set_ui' prog.cpp:(.text+0x1d3): undefined reference to `__gmpz_init_set_ui' prog.cpp:(.text+0x1fa): undefined reference to `__gmpz_add' prog.cpp:(.text+0x218): undefined reference to `__gmpz_set_ui' prog.cpp:(.text+0x22a): undefined reference to `__gmpz_mul_2exp' prog.cpp:(.text+0x23d): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x26d): undefined reference to `__gmpz_mul' prog.cpp:(.text+0x283): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x2d8): undefined reference to `__gmpz_init' prog.cpp:(.text+0x2f2): undefined reference to `__gmpz_init' prog.cpp:(.text+0x30d): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x329): undefined reference to `__gmpz_init' prog.cpp:(.text+0x33c): undefined reference to `__gmpz_init' prog.cpp:(.text+0x359): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x36f): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x390): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x3a6): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x3e1): undefined reference to `__gmpz_clear' /home/9Y3VA6/ccCRpjg7.o: In function `valid_digit(int)': prog.cpp:(.text+0x480): undefined reference to `__gmpz_init' prog.cpp:(.text+0x4c2): undefined reference to `__gmpz_set_ui' prog.cpp:(.text+0x4cf): undefined reference to `__gmpz_init_set_ui' prog.cpp:(.text+0x4fd): undefined reference to `__gmpz_add' prog.cpp:(.text+0x518): undefined reference to `__gmpz_set_ui' prog.cpp:(.text+0x52d): undefined reference to `__gmpz_mul_2exp' prog.cpp:(.text+0x548): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x57b): undefined reference to `__gmpz_cmp' prog.cpp:(.text+0x588): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x5e5): undefined reference to `__gmpz_init' prog.cpp:(.text+0x601): undefined reference to `__gmpz_set_ui' prog.cpp:(.text+0x60e): undefined reference to `__gmpz_init_set_ui' prog.cpp:(.text+0x632): undefined reference to `__gmpz_add' prog.cpp:(.text+0x657): undefined reference to `__gmpz_set_ui' prog.cpp:(.text+0x669): undefined reference to `__gmpz_mul_2exp' prog.cpp:(.text+0x67d): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x6b0): undefined reference to `__gmpz_cmp' prog.cpp:(.text+0x6bd): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x6d3): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x6e9): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x782): undefined reference to `__gmpz_init' prog.cpp:(.text+0x79c): undefined reference to `__gmpz_init' prog.cpp:(.text+0x7b0): undefined reference to `__gmpz_init' prog.cpp:(.text+0x7fc): undefined reference to `__gmpz_init' prog.cpp:(.text+0x832): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x848): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x86d): undefined reference to `__gmpz_clear' prog.cpp:(.text+0x883): undefined reference to `__gmpz_clear' collect2: error: ld returned 1 exit status
Standard output is empty