/* vim: set ts=4 sts=4 sw=4 si foldmethod=marker: */ // {{{ includes // IO #include #include #include #include #include // Utility #include #include #include #include #include #include #include #include // Data structures #include #include #include #include #include #include #include #include // I want easy access to STL and things like hash_map using namespace std; using namespace std::tr1; using namespace __gnu_cxx; // Needed for hash_map namespace __gnu_cxx { template<> struct hash { size_t operator()(const std::string& x) const { return hash()(x.c_str()); } }; } // }}} // {{{ utility routines and such // stolen from http://www.ddj.com/cpp/184403801 template class StringTok { public: StringTok(const T& seq, typename T::size_type pos = 0) : seq_(seq) , pos_(pos) { } T operator()(const T& delim); private: const T& seq_; typename T::size_type pos_; }; template T StringTok::operator()(const T& delim) { T token; if(pos_ != T::npos) { // start of found token typename T::size_type first(seq_.find_first_not_of(delim.c_str(), pos_)); if (first != T::npos) { // length of found token typename T::size_type num(seq_.find_first_of(delim.c_str(), first) - first); // do all the work off to the side token = seq_.substr(first, num); // done; now commit using // nonthrowing operations only pos_ = first + num; if (pos_ != T::npos) ++pos_; if (pos_ >= seq_.size()) pos_ = T::npos; } } return token; } // stolen from http://www.gotw.ca/gotw/029.htm for case-insensitive lexicographic compares struct ci_char_traits : public std::char_traits { static bool eq(char c1, char c2) { return toupper(c1) == toupper(c2); } static bool ne(char c1, char c2) { return toupper(c1) != toupper(c2); } static bool lt(char c1, char c2) { return toupper(c1) < toupper(c2); } static int compare(const char* s1, const char* s2, size_t n) { return strncasecmp(s1, s2, n); } static const char* find(const char* s, int n, char a) { while(n-- > 0 && toupper(*s) != toupper(a)) { ++s; } return s; } }; // no boost makes c++ angry; lexical cast comes in handy for string <=> int conversion without expliucitly writing out the streams all the time. template T lexical_cast(const S& arg) { stringstream interpreter; T result; if (!(interpreter << arg) || !(interpreter >> result) || !(interpreter >> std::ws).eof()) throw logic_error("bad lexical_cast"); return result; } // }}} // {{{ utility typedefs typedef vector vs; typedef vector vi; typedef std::basic_string ci_string; // }}} // {{{ problem-specific typedefs // }}} int main() { const long double log2l10(log2l(10)); long double n; while (cin >> n) { const long double log2ln(log2l(n)); const long double log2lnp1(log2l(n+1)); for (long double x(floorl(log10l(n)) + 2);; ++x) { const uint32_t a(static_cast(ceill(log2ln + x * log2l10))); if (a != static_cast(ceill(log2lnp1 + x * log2l10))) { cout << a << endl; break; } } } return 0; }