bakku-numbers
Source: hackerearth
Difficulty: EASY

Aklank is fond of numbers which are divisible by either P1 or P2. He termed those numbers as Bakku numbers. Recently his best friend gave him a range of numbers. Now he is wondering what is the probability of finding Bakku numbers from that range of numbers.

Input
First line of input contains two integers P1 and P2 (2 ≤ P1 ≤ 10000, 2 ≤ P2 ≤ 10000) — both P1 and P2 are prime numbers.

Second line of the input contains an integer T  (1 ≤ T ≤ 100000) — the number of test cases.

Each of the next T lines contains two integers - L and R (1 ≤ L ≤ R ≤ 100,00,00,000) - the starting number and ending number of each range from where he will search for Bakku numbers (inclusive).

Output
Print T lines for each test case.

In each line print answer with up to 6 digits after decimal point.

SAMPLE INPUT
3 5
2
1 10
20 34

SAMPLE OUTPUT
0.500000
0.466667

Explanation

First Case : Numbers divisible by 3 or 5 are 3, 5, 6, 9, 10

Second Case : Numbers divisible by 3 or 5 are 20, 21, 24, 25, 27, 30, 33


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
from sys import stdin
ar = list(map(int, stdin.readline().strip().split()))
p1 = ar[0]
p2 = ar[1]
t = int(stdin.readline().strip())
#print p1, p2, t
for i in range(0, t, 1):
	ar = list(map(int, stdin.readline().strip().split()))
	l = ar[0]
	r = ar[1]
	t1 = 0
	t1 = r/p1 - l/p1
	if l%p1==0:
		t1 += 1
	#print t1
	
	t2 = r/p2 - l/p2
	if l%p2==0:
		t2 += 1
	#print t2
	
	com = p1*p2
	t3 = r/com - l/com
	if l%com==0:
		t3+=1
	#print t3
	x = t1+t2-t3
	val = x/float(r-l+1)
	#print val
	g = '%0.6f' %val
	print(g)


from fractions import gcd;
a,b=list(map(int,input().split()));
q=gcd(a,b);	l=(a*b)/q;
for _ in range(int(input())):	
	n,m=list(map(int,input().split()));	n-=1;
	x= ( (m/a + m/b - m/l) - (n/a + n/b - n/l) );
	z= x/float((m-n))
	print(("%.6f" % z))


from fractions import gcd;
a,b=list(map(int,input().split()));
q=gcd(a,b);	l=(a*b)/q;
for _ in range(int(input())):	
	n,m=list(map(int,input().split()));	n-=1;
	x= ( (m/a + m/b - m/l) - (n/a + n/b - n/l) );
	z= x/float((m-n))
	print(("%.6f" % z))


from sys import stdin

def main():
	nextint = iter(map(int, stdin.read().split())).__next__
	p1, p2 = nextint(), nextint()
	for _ in range(nextint()):
		l, r = nextint(), nextint()
		p1facs = len(range(p1, r + 1, p1)) - len(range(p1, l, p1))
		p2facs = len(range(p2, r + 1, p2)) - len(range(p2, l, p2))
		p1p2facs = len(range(p1*p2, r + 1, p1*p2)) - len(range(p1*p2, l, p1*p2))
		print("{:.6f}".format(round((p1facs + p2facs - p1p2facs) / float(r - l + 1), 6)))

main()