UVa 474 - Heads / Tails Probability

Problem Number - Problem Name

 * problem Number : 474 : head/Tail probability
 * problem Number : 545 : head

Summary

 * the problem is that find out the 2^-n value and print it correct format. that's all.

Explanation
we have a function printf. where we can print 2^-n but its format x.xxx e-XXX. so we have to follow another way to solve this problem.

Gotchas

 * Main logic output highest value is 5.000e-1. because 2^-1 is highest value within range
 * So we know, the number of digit 2^-n. i.e digit = floor (log (2^n)+1) = floor[ nlog2+1). Digit is the power of (e-).
 * Now we have to find the portion 5.000, we know ½ =0.5 , digit = floor[ 2log2+1] = 1 , so r = ½ *102
 * r = 2^-n*10^digit
 * log(r) = -nlog(2)+digit*log(10)
 * log(r) = -nlog2 + digit*log(5)+digit*log(2)
 * log(r) = (digit-n)log(2)+digit*log(5)
 * r = exp((digit-n)*log(2) +digit*log(5)).
 * Printf( 2^n = r e- digit);
 * ok

Implementations
Grate implementation on Exponential Calculation.

Input
Sample Input

1 100 10000 1000000

Output
2^-1 = 5.000e-1 2^-100 = 7.889e-31 2^-10000 = 5.012e-3011 2^-1000000 = 1.010e-301030

Discussed by
Rizoan Tiufiq

Categories here, use the form , see Categories for a list