# UVa 11809 - Floating-Point Numbers

x1 * 2 ^n = x2 * 10^ k

log10(x1) + n * log10(2) = log10(x2) + k.

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define MAXN 50
#define EPS 0.0001
using namespace std;

char ss[MAXN];

const int E[MAXN] = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383,
32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431,
67108863, 134217727, 268435455, 536870911, 1073741823};

const double M[MAXN] = {0.500000000000000, 0.750000000000000, 0.875000000000000, 0.937500000000000,
0.968750000000000, 0.984375000000000, 0.992187500000000, 0.996093750000000, 0.998046875000000,
0.999023437500000, 0.999511718750000};

int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
while(cin >> ss&& strlen(ss) != 3) {
ss[17] = ' ';
int n, k;
double x1, x2, t;
sscanf(ss, "%lf", &x2);
sscanf(ss + 17, "%d", &k);
t = log10(x2) + k;
//        printf("%llf %d\n", x2, k);
for(int i = 0; i <= 9; i++) {
for(int j = 1; j <= 30; j++) {
//                printf("%lf\n", fabs((log10(M[i]) + E[j] * log10(2)) - t));
if(fabs((log10(M[i]) + E[j] * log10(2)) - t) < EPS)
printf("%d %d\n", i, j);
}
}
memset(ss, 0, sizeof(ss));
}
return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define MAXN 50
#define EPS 0.0001
using namespace std;

char ss[MAXN], t[MAXN];
double M[MAXN][MAXN];
long long E[MAXN][MAXN];

int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
for(int i = 0; i <= 9; i++) {
for(int j = 1; j <= 30; j++) {
double x1 = 1 - 1.0 / (1 << (i + 1));
long long n = (1 << j) - 1;
double t = log10(x1) + n * log10(2);
E[i][j] = t;
M[i][j] = pow(10, t - E[i][j]);
}
}
while(gets(ss)&&(strlen(ss) != 3)) {
double x2;
long long k;
for(int i = 0; i < 18; i++)
t[i] = ss[i];
sscanf(t, "%lf", &x2);
sscanf(ss + 18, "%lld", &k);
for(int i = 0; i <= 9; i++) {
for(int j = 1; j <= 30; j++) {
if(k == E[i][j]&& fabs(x2 - M[i][j]) < EPS)
printf("%d %d\n", i, j);
}
}
memset(t, 0, sizeof(t));
memset(ss, 0, sizeof(ss));
}
return 0;
}