Find the probability of getting a 1-bit number ?

By | February 19, 2017

Find the probability of getting a 1bit number ?


Find the probability of getting a 1-bit number after the following procedure is followed:

Initially a number x is chosen at random in a given range .After this we again choose a bit from x randomly?

Find the expected number of bit 1s if we randomly choose a number x in the given range?


Explanation 


 Input Format

The first line of input is the number of test cases T. Each test cases is a line contains 2 integers A and B separated by a space.

Output Format

For each test case output a line containing 2 float numbers separated by a space. The first one is the probability and the second one is the expected number. You should output the number accurate to 5 fractional digits.

Constraints

1 <= T <= 200

1 <= A <= B <= 10^10

Sample Input

1

2 4

Sample Output

0.61111

1.33333

Explanation

(10) (11) (100)

(1) So we got a one in :

(1/3)(1/2)+(1/3)(1/1)+(1/3)*(1/3)=(11/18)

(2) The expected 1 we have is

(1)(1/3)+(2)(1/3)+(1)*(1/3)=(4/3)

Time Limit:3.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB

SOURCE CODE ::

 

OUTPUT : :

 

 

Leave a Reply