utkarsh-and-faulty-rain-gauge-february-easy-1

Utkarsh is going to Cherrapunji to visit his brother Saharsh. Cherrapunji faces one of largest rainfall in the country. So, Saharsh and Utkarsh decided to measure this rainfall by T Rain Gauges. They were going to measure it by taking the product of the readings of all the gauges. But, they found out that the gauges were not working properly and were producing random values. The brothers want to know what will be the expected result of the experiment.

The i^th Rain Gauge has a least count of 1/Ri units. It has Ni divisions on its surface. Formally, it can give any reading from the set {0, 1/Ri , 2/Ri , ... ,Ni/Ri}. It gives a reading x with a probability proportional to x^2. 
Input Format:
The first line contains the integer T.
T lines follow each containing 2 integers - Ni and Ri.  
Output format:
Print the answer to the problem as real number exactly 4 decimal places. It is guaranteed that the answer is always less than 10^9.
Constraints:
1 ≤ T ≤ 10^3
1 ≤ Ni ≤ 10^3 
1 ≤ Ri ≤ 10^3

NOTE:
 A function p(x) is said to be proportional to  x^2 means p(x) = ax^2 for some non negative a.
All the rain gauges produce values independently from each other.

SAMPLE INPUT
2
2 4
2 5

SAMPLE OUTPUT
0.1620

Explanation

First gauge produces output 
1/4 with probability = 0.2
2/4 with probability = 0.8  

Second gauge produces output 
1/5 with probability = 0.2
2/5 with probability = 0.8

The product is 1/4 * 1/5 ( = 0.05) with a probability of 0.2 * 0.2 ( = 0.04)
The product is 1/4 * 2/5 ( = 0.1) with a probability of 0.2 * 0.8 ( = 0.16)
The product is 2/4 * 1/5 ( = 0.1) with a probability of 0.8 * 0.2 ( = 0.16)
The product is 2/4 * 2/5 ( = 0.2) with a probability of 0.8 * 0.8 ( = 0.64)

Therefore the result is 
0.05 with probability = 0.04  
0.1 with probability = .016+0.16 = 0.32  
0.2 with probability = 0.64  

The Expected Result is therefore = 0.05 * 0.04 + 0.1 * 0.32 + 0.2 * 0.64 = 0.1620

Source: hackerearth | Difficulty: EASY


Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
s = 1
for _ in range(int(input())):
	n, r = list(map(int, input().split()))
	s *= sum([(x / float(r))**3 for x in range(n + 1)]) / sum([(x / float(r))**2 for x in range(n + 1)])
 
print("%.4f" % s)


s = 1
for _ in range(int(input())):
	n, r = list(map(int, input().split()))
	s *= sum([(x / float(r))**3 for x in range(n + 1)]) / sum([(x / float(r))**2 for x in range(n + 1)])

print("%.4f" % s)


'''
https://www.hackerearth.com/february-easy-16/algorithm/utkarsh-and-faulty-rain-gauge-february-easy-1/
'''

T = int(eval(input()))
expected_value_list=[]
for x in range(T):
	N,R = [int(x) for x in input().strip().split()]
	a = R*R*6.0/(N * (N+1)*(2*N+1))
	expected_value_list.append((a/R**3) * (N * (N +1)/2) ** 2)

result = 1
for val in expected_value_list:
	result *= val
print(('%.4f'%(result,)))




T = int(input())
ans = 1
for i in range(T):
	n, r = list(map(int, input().split()))
	x, y = 0, 0
	for j in range(1,n+1):
		z = (j*1.0)/(r*1.0)
		x = x + z**3
		y = y + z**2
	x = x/y
	ans = ans * x
print("%.4f" % ans)


s = 1
for _ in range(int(input())):
	n, r = list(map(int, input().split()))
	s *= sum([(x / float(r))**3 for x in range(n + 1)]) / sum([(x / float(r))**2 for x in range(n + 1)])

print("%.4f" % s)