mani-and-pane-1

Mani wants to eat chocolates, but her brother Pane does not give her the chocolates easily. Pane being a mathematician wants to teach Mani an important concept. Pane makes Mani stand on an infinite straight line. He marks all integers at equal divisions on the line and places chocolates on the integer X.

Initially Mani is on an integer Z. Mani can jump forward or backward from any general integer K. Pane being a mischievous brother puts a constraint that Mani can jump forward or backward only A, B or C integers i.e from any general integer K there are 6 possible moves (K+A, K-A, K+B, K-B, K+C, K-C). Pane gives Mani the liberty to choose distinct A, B and C in the range [1,100]. Find the probability that Mani succeeds in reaching the chocolates. Note that Mani is really clever and if she can reach the chocolates, she will.

Input :

First line contains an integer T containing test cases.
Each test case consists of a single line with two integers X and Z.

Output :

A single line for each test case having the answer rounded off to exactly 6 digits after the decimal.

Constraints :

1 ≤ T ≤ 10^5

1 ≤ X,Z ≤ 2 * 10^18

1 ≤ A,B,C ≤ 100

Author : Sayan

Tester : Shreyans

(By IIT Kgp HackerEarth Programming Club)

SAMPLE INPUT
3
2 10
15758 29586685
1000 1000000000

SAMPLE OUTPUT
0.956092
0.839450
0.999716

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
'''def gcd(a,b):
	if a%b==0:
		return b
	elif b%a==0:
		return a
	else:
		if a>b:
			return gcd(a%b,b)
		else:
			return gcd(a,b%a)
array=[]
for i in range(100):
	array.append(0)
for i in range(1,101):
	for j in range(1,101):
		#if j==i:
		#    continue
		for k in range(1,101):
			if k==j or k==i or j==i:
				continue
			else:
				a=i;b=j;c=k
				array[gcd(gcd(a,b),c)-1]+=1
print array
print sum(array)'''
nooftest=eval(input())
array=[814434, 99888, 28302, 12102, 5982, 2958, 1950, 1176, 924, 654, 474, 312, 204, 204, 114, 114, 60, 60, 60, 60, 24, 24, 24, 24, 24, 6, 6, 6, 6, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(nooftest):
	z,x=list(map(int,input().split()))
	n=abs(z-x)
	ans=0
	for j in range(1,101):
		if n%j==0:
			ans+=array[j-1]
	a=ans/970200.0
	print(("%.6f" % round(a,6)))


def gcd(a,b):
	if(a==0):
		return b;
	elif(b==0):
		return a;
	elif(a>b):
		return gcd(a%b,b);
	else:
		return gcd(a,b%a);


dp=[];
g = 0;
g1 = 0;
su = 0;
for i in range(102):
	dp.append(0);

for i in range(1,101):
	for j in range(i+1,101):
		g = gcd(i,j);
		for k in range(j+1,101):
			g1 = gcd(g,k);
			dp[g1] = dp[g1]+1;
			su = su+1;

su = float(su);

t = eval(input());

for i in range(t):
	a,b = input().split();
	a,b = int(a),int(b);
	s = 0;
	x = max(a,b)-min(a,b);
	for j in range(1,101):
		if(x%j==0):
			s = s + dp[j];
	s = float(s);
	print("%.6f" %(s/su));