/*这题一开始用约瑟环的递推公式做,发现无限的超时,果断打表一看,前五十如下: 1 1 2 1 3 3 4 1 5 3 6 5 7 7 8 1 9 3 10 5 11 7 12 9 13 11 14 13 15 15 16 1 17 3 18 5 19 7 ... 规律出来了,先用等比求和算出在第几个循环里面,再用等差数列递推式算出是该循环的第几个值*/ #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; int x,z; long long n; long long optimized_pow_n(long long x, unsigned int n) { long long pw = 1; while (n > 0) { if (n & 1) // n & 1 等价于 (n % 2) == 1 pw *= x; x *= x; n >>= 1; // n >>= 1 等价于 n /= 2 } return pw; } int main() { char str; while(scanf("%d%c%d",&x,&str,&z)) { if(x == 0 && z == 0) break; n = x * optimized_pow_n(10,z); //printf("%lld**\n",n); long long ansp; for(int i = 0; i != -1; i++) { long long a; a = optimized_pow_n(2,i-1) - 1; if(n <= (a+1)*2 - 1) { n = n - a; break; } } printf("%lld\n",1 + 2 * (n - 1)); } return 0; }