// The archeologist's dilemma (archaeological annoyance) // PC/Ultraviolet IDs: 110503/701, popularity: A, success rate: Low Level: 1 // verdict: accepted // submission date: 2011-05-29 // UV Run Time: 0.212 S // All Rights Reserved (c) 2011, Qiu. Metaphysis # Yeah dot net //// Algorithm : The power of brute force computing 2 will soon reach the upper bound of the integer representation, unless calculated using an alternative method. The following shows two methods. One method is to calculate the power of 2 until the given digit is found. This method can calculate the result, however, it is easy to exceed the 10 S // time limit and memory limit. The second method is based on the following inequality (assuming that the dropped number has a total of K bits, the existing number is N, and the minimum power to be // calculated is X ): /// N * 10 ^ k <2 ^ x <(n + 1) * 10 ^ K // (logn + k)/log2) <x <(log (n + 1) + k)/log2) // The second method can obtain the AC, but for a relatively large number, the computing time is still long. Because the power Number of 2 is infinite, // it cannot be determined whether NO x meets the given conditions, so no power of 2 cannot be output ". # Include <iostream> # include <cmath> using namespace STD; void find_smallest_exponent_by_brute_force (long number) {long unsigned exponent = 7; string first; while (number) {first. append (1, '0' + Number % 10); Number/= 10;} string result = "821"; while (result. rfind (first )! = (String: size_type) (result. length ()-first. length () | result. length () <(2 * first. length () + 1) {int carry = 0; For (INT I = 0; I <result. length (); I ++) {carry = 2 * (result [I]-'0') + carry; Result [I] = '0' + carry % 10; carry = carry/10;} If (carry) result. append (1, '1'); exponent ++;} cout <exponent <Endl;} void find_smallest_exponent_by_log (long number) {int digits = 0; long original = number; while (original) {digits ++; original/= 10 ;}for (int K = (digits + 1); k ++) {long down = floor (log10 (number) + k)/log10 (2); long up = floor (log10 (number + 1) + k) /log10 (2); If (up> down) {cout <up <Endl; return ;}} int main (int ac, char * AV []) {long number; while (CIN> Number) find_smallest_exponent_by_log (number); Return 0 ;}