fork download
  1. /*
  2.  * if you are interested in the reference code here,
  3.  * see https://g...content-available-to-author-only...b.com/georeth/OJLIBS for more information
  4.  *
  5.  * Solution Author : Georeth Chow <georeth2010@gmail.com>
  6.  */
  7. #include <cstdio>
  8. #include <cmath>
  9. #include <cstring> // memset
  10. #include <cstdlib> // malloc
  11. #include <cstdint> // int64_t
  12. #include <cinttypes> // PRId64 SCNd64
  13. #include <numeric> // accumulate, partial_sum, inner_product, iota, adjacent_difference
  14. #include <vector>
  15. #include <map>
  16. #include <set>
  17. #include <tuple> // pair, tuple
  18. #include <iostream>
  19. #include <algorithm>
  20. #include <utility>
  21. #include <iterator>
  22. template <typename It>
  23. struct iter_range : std::pair<It, It> {
  24. typedef std::pair<It, It> base_t;
  25. using base_t::base_t;
  26. It begin() { return base_t::first; }
  27. It end() { return base_t::second; }
  28. };
  29. template <typename It>
  30. iter_range<std::reverse_iterator<It>> rev(const iter_range<It> &origin) {
  31. using rev_t = std::reverse_iterator<It>;
  32. return {rev_t(origin.second), rev_t(origin.first)};
  33. }
  34. template <typename Int = int>
  35. struct int_iter {
  36. Int i;
  37. explicit int_iter(Int i = 0) : i(i) { }
  38. Int operator*() const { return i; }
  39. int_iter &operator++() { ++i; return *this; }
  40. int_iter &operator--() { --i; return *this; }
  41. int_iter operator+(Int step) const { return int_iter(i + step); }
  42. int_iter operator-(Int step) const { return int_iter(i - step); }
  43. Int operator-(const int_iter &that) const { return i - that.i; }
  44. int_iter &operator+=(Int step) { i += step; return *this; }
  45. int_iter &operator-=(Int step) { i -= step; return *this; }
  46. bool operator==(const int_iter &that) const { return i == that.i; }
  47. bool operator!=(const int_iter &that) const { return !(*this == that); }
  48. Int operator[](Int n) { return i + n; }
  49. typedef Int difference_type;
  50. typedef Int value_type;
  51. typedef Int *pointer;
  52. typedef Int reference; // not a int container, never reference to int
  53. typedef std::random_access_iterator_tag iterator_category;
  54. };
  55. typedef iter_range<int_iter<>> range_t;
  56. range_t range(int b, int e) { return {int_iter<>(b), int_iter<>(e > b ? e : b)}; }
  57. range_t range(int n) { return range(0, n); }
  58. range_t nrange(int n) { return range(1, n+1); }
  59. range_t inrange(int b, int e) { return range(b, e + 1); }
  60. using namespace std; // use as solution header. name polution is fine.
  61. #ifdef LOCAL_JUDGE
  62. # define pr_debug(...) fprintf(stderr, __VA_ARGS__)
  63. #else
  64. # define pr_debug(...)
  65. #endif
  66. template <typename T>
  67. bool chmax(T &m, const T &v) { if (v > m) return m = v, true; return false; }
  68. template <typename T>
  69. bool chmin(T &m, const T &v) { if (v < m) return m = v, true; return false; }
  70. void fio() {
  71. ios_base::sync_with_stdio(false);
  72. cin.tie(nullptr);
  73. cout.tie(nullptr);
  74. }
  75. #include <boost/multiprecision/gmp.hpp>
  76. using namespace boost::multiprecision;
  77. /* ===== SOLUTION START ===== */
  78. typedef int_iter<int64_t> ll_it;
  79. int64_t N;
  80. int64_t ValidB;
  81. mpz_int all_ones(int nd, int64_t B) {
  82. mpz_int p(1);
  83. mpz_int ans = 0;
  84. while (nd--) {
  85. ans += p;
  86. p *= B;
  87. }
  88. return ans;
  89. }
  90. void valid_digit(int nd) {
  91. lower_bound(ll_it(2LL), ll_it(numeric_limits<int64_t>::max()), N, [=](int64_t B, int64_t N) {
  92. mpz_int num = all_ones(nd, B);
  93. if (num == N) chmin(ValidB, B);
  94. return all_ones(nd, B) < N;
  95. });
  96. }
  97. void solve() {
  98. cin >> N;
  99. ValidB = N - 1;
  100. for (int i : nrange(64))
  101. valid_digit(i);
  102. cout << ValidB << endl;
  103. }
  104. int main() {
  105. int T;
  106. cin >> T;
  107. for (int i : nrange(T)) {
  108. cout << "Case #" << i << ": ";
  109. solve();
  110. }
  111. return 0;
  112. }
  113.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/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
stdout
Standard output is empty