2012-05-13 16:44:09Morris

[UVA][Math] 545 - Heads


 Heads 

The probability of n heads in a row tossing a fair coin is 2-n

Input 

The first line of the input contains an integer r. Then r lines containing each one an integer number n. The valueof n is as follows:$0< n le 9000$.

Output 

Print r lines each with the value of 2-n for the given values of n, using the format:


2^-n = x.xxxE-y


where each x is a decimal digit and each y is a decimal integer with no leading zeroes or spaces.

Sample Input 

3
8271
6000
1

Sample Output 

2^-8271 = 1.517E-2490
2^-6000 = 6.607E-1807
2^-1 = 5.000E-1



#include <stdio.h>
#include <math.h>
int main() {
int t, n;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
int e = (int)floor(-n*log10(2));
printf("2^%d = %.3lfE%d\n", -n, pow(10, -n*log10(2)-e), e);
}
return 0;
}