Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.

Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo. 


-----Input-----

The first line of input contains a single integer N (1 ≤ N ≤ 16).

The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].


-----Output-----

Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10^{ - 4}.


-----Examples-----
Input
1
2
0

Output
0.500000

Input
2
2 3
1 0

Output
0.666667

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Implementation


Solutions:
3
from fractions import gcd

def main():
	n = int(input())
	m = list(map(int, input().split()))
	r = list(map(int, input().split()))
	k = 1
	for x in m:
		k = x * k // gcd(x, k)
	a = 0
	for i in range(k):
		f = 0
		for j in range(n):
			if i % m[j] == r[j]:
				f = 1
				break
		a += f
	print(a / k)
main()


from math import sqrt
input()
m = list(map(int, input().split()))
r = list(map(int, input().split()))

def diver(x):
	c = 2
	while c * c <= x:
		if x % c == 0:
			print(c, end=' ')
			x //= c
		else:
			c += 1
	print(x)
washed = 0
for d in range(720720 + 1):
	res_d = False
	for i in range(len(m)):
		if d % m[i] == r[i]:
			res_d = True
			break
	if res_d:
		washed += 1
print(washed / 720721)


input()
f = lambda : map(int, input().split())
(T, l) = (720720, list(zip(f(), f())))
print(sum((any((d % m == r for (m, r) in l)) for d in range(T))) / T)


class CodeforcesTask656BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.m = []
		self.r = []

	def read_input(self):
		self.n = int(input())
		self.m = [int(x) for x in input().split(' ')]
		self.r = [int(x) for x in input().split(' ')]

	def process_task(self):
		bad_days = 0
		for day in range(10 ** 5):
			for x in range(self.n):
				if day % self.m[x] == self.r[x]:
					bad_days += 1
					break
		self.result = str(bad_days / 10 ** 5)

	def get_result(self):
		return self.result
Solution = CodeforcesTask656BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
count = 0
for i in range(200000):
	for j in range(n):
		if i % m[j] == r[j]:
			count += 1
			break
print(count / 200000)


from fractions import gcd
from functools import reduce
from operator import mul
n = int(input())
m = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
lcm = m[0]
if len(m) > 1:
	lcm = reduce(mul, m, 1) // reduce(gcd, m, 0)
res = 0
for d in range(min(lcm, 100000)):
	for i in range(n):
		if d % m[i] == r[i]:
			res += 1
			break
print(res / min(lcm, 100000))


from functools import reduce

def gcd(x, y):
	return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
	return x // gcd(x, y) * y
N = int(input())
M = list(map(int, input().split()))
R = list(map(int, input().split()))
d = reduce(lcm, M)
cnt = 0
for i in range(d):
	qq = False
	for j in range(N):
		qq |= i % M[j] == R[j]
	cnt += qq
print(cnt / d)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = 0
for D in range(100000):
	for i in range(n):
		if D % a[i] == b[i]:
			A += 1
			break
print(A / 100000)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
n = int(input())
M = list(map(int, input().split()))
R = list(map(int, input().split()))
G = 1
for m in M:
	G = G * m // gcd(G, m)
count = 0
for d in range(G):
	for i in range(len(M)):
		if d % M[i] == R[i]:
			count += 1
			break
print(count / G)


n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
result = 0
for d in range(100000):
	for i in range(n):
		if d % m[i] == r[i]:
			result += 1
			break
print('%.6f' % (result / 100000))


def main():
	input()
	w = 30030
	l = [0] * w
	for (m, r) in zip(map(int, input().split()), map(int, input().split())):
		l[r:w:m] = [1] * ((w - r + m - 1) // m)
	print(sum(l) / w)
main()


n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
days = [0 for i in range(30030)]
d = 0
for mi in range(n):
	for i in range(30030):
		if (i + 1) % m[mi] == r[mi]:
			if days[i] != 1:
				d += 1
			days[i] = 1
print('%.6f' % (d / 30030))


n = int(input())
M = list(map(int, input().split()))
R = list(map(int, input().split()))
Max = 100000
answer = 0
for i in range(Max):
	for j in range(n):
		if i % M[j] == R[j]:
			answer += 1
			break
print(answer / Max)


ans = 0.0
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
d = list((0 for i in range(50000)))
for i in range(len(m)):
	num = m[i]
	for j in range(num - r[i], 50001, num):
		d[j - 1] = 1
print(round(sum(d) / 50000, 10))


from math import gcd
from functools import reduce
N = int(input())
M = list(map(int, input().split(' ')))
R = list(map(int, input().split(' ')))
n = reduce(lambda x, y: x * y // gcd(x, y), M, 1)
tot = 0
for i in range(n):
	for j in range(N):
		if (i - R[j]) % M[j] == 0:
			tot = tot + 1
			break
print(tot / n)


import re
import inspect
from sys import argv, exit

def rstr():
	return input()

def rint():
	return int(input())

def rints(splitchar=' '):
	return [int(i) for i in input().split(splitchar)]

def varnames(obj, namespace=globals()):
	return [name for name in namespace if namespace[name] is obj]

def pvar(var, override=False):
	prnt(varnames(var), var)

def prnt(*args, override=False):
	if '-v' in argv or override:
		print(*args)
n = rint()
M = rints()
R = rints()
prnt(n, M, R)
done = 0
totaldays = 100000
day = 0
while day < totaldays:
	for (m, r) in zip(M, R):
		if day % m == r:
			done += 1
			break
	day += 1
pvar(done)
print(done / totaldays)


n = int(input())
M = [int(x) for x in input().split()]
R = [int(x) for x in input().split()]
ans = 0
for d in range(100000):
	for i in range(n):
		if d % M[i] == R[i]:
			ans += 1
			break
print(ans / 100000)


n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
days = 0
for day in range(1, 100001):
	for index in range(n):
		if day % m[index] == r[index]:
			days += 1
			break
print(days / 100000)


f = lambda : map(int, input().split())
f()
k = 720720
t = [0] * k
for (m, r) in zip(f(), f()):
	t[r::m] = [1] * (k // m)
print(sum(t) / k)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
l = 1
s = set()
for i in range(n):
	l = lcm(l, m[i])
for k in range(l // min(m) + 1):
	for j in range(n):
		if m[j] * k + r[j] <= l:
			s.add(m[j] * k + r[j])
if 0 in s:
	s.remove(0)
q = len(s)
print(q / l)


n = int(input())
ms = list(map(int, input().split()))
rs = list(map(int, input().split()))
a = 0
N = 365 * 100
for D in range(1, N + 1):
	for i in range(n):
		if D % ms[i] == rs[i]:
			a += 1
			break
print(a / N)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
alx = 111111
cnt = 0
for i in range(alx + 1):
	for j in range(n):
		if i % a[j] == b[j]:
			cnt += 1
			break
print(round(cnt / alx, 6))


n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
k = 0
for i in range(100000):
	for j in range(n):
		if i % m[j] == r[j]:
			k += 1
			break
print(k / 100000)


from math import *

def find_lcm(num1, num2):
	g = gcd(num1, num2)
	lcm = int(int(num1 * num2) / int(g))
	return lcm
n = int(input())
r = list(map(int, input().split()))
m = list(map(int, input().split()))
if n == 1:
	lcm = r[0]
else:
	lcm = find_lcm(r[0], r[1])
	for i in range(2, n):
		lcm = find_lcm(lcm, r[i])
cnt = 0
for i in range(lcm):
	for j in range(n):
		if i % r[j] == m[j]:
			cnt += 1
			break
print(cnt / lcm)


n = int(input())
m = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]

def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)
nsk = 1
for x in m:
	nsk = nsk * x // gcd(nsk, x)
res = 0
for i in range(nsk):
	aaa = False
	for j in range(n):
		if i % m[j] == r[j]:
			aaa = True
			break
	if aaa:
		res += 1
print(res / nsk)


N = int(input())
M = list(map(int, input().split()))
R = list(map(int, input().split()))

def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)
lcm = 1
for i in range(N):
	lcm = lcm * M[i] / gcd(lcm, M[i])
rec = set()
for i in range(N):
	j = R[i]
	while j < lcm:
		rec.add(j)
		j += M[i]
print(len(rec) / lcm)


def b():
	n = int(input())
	d = []
	r = []
	count = 0.0
	d = input().split(' ')
	r = input().split(' ')
	for i in range(100000):
		for j in range(n):
			if i % int(d[j]) == int(r[j]):
				count += 1e-05
				break
	print(round(count, 6))
b()


n = int(input())
m = [int(i) for i in input().split(' ')]
r = [int(i) for i in input().split(' ')]
L = 720720
ans = 0
for i in range(L):
	for (j, k) in zip(m, r):
		if i % j == k:
			ans += 1
			break
print(ans / L)


n = int(input())
M = [int(s) for s in input().split()]
R = [int(s) for s in input().split()]
c = 0
for i in range(100000):
	bool = False
	for j in range(n):
		if i % M[j] == R[j]:
			bool = True
			break
	if bool:
		c += 1
print(c / 100000)


def gcd(x, y):
	while x != 0 and y != 0:
		if x > y:
			x %= y
		else:
			y %= x
	return x + y

def lcm(x, y):
	return x * y / gcd(x, y)
n = int(input())
m = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
l = 1
for i in range(n):
	l = lcm(l, m[i])
s = set()
for i in range(n):
	t = int(l / m[i])
	for j in range(t):
		s.add(r[i] + m[i] * j)
print(len(s) / l)


def should_wash(r, m, d):
	return any((d % mm == rr for (mm, rr) in zip(m, r)))

def main():
	input()
	m = [int(x) for x in input().split()]
	r = [int(x) for x in input().split()]
	cnt = 0
	t = 100000
	for i in range(t):
		if should_wash(r, m, i):
			cnt += 1
	print(cnt / t)
main()


ct = 0
x = int(input())
y = list(map(int, input().split(' ')))
z = list(map(int, input().split(' ')))
for i in range(1, 720721):
	for j in range(x):
		if i % y[j] == z[j]:
			ct += 1
			break
print(ct / 720720)


from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)

def get_lcm(m):
	_lcm = lcm(m[0], m[1])
	for i in range(2, len(m)):
		_lcm = lcm(_lcm, m[i])
	return _lcm
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
if n == 1:
	print(1 / m[0])
else:
	l = get_lcm(m)
	ans = 0
	for i in range(l):
		ok = 0
		for j in range(len(m)):
			if i % m[j] == r[j]:
				ok = 1
		ans += ok
	print(ans / l)


def gcd(a, b):
	while b != 0:
		c = a % b
		a = b
		b = c
	return a
input()
m = list(map(int, input().split()))
r = list(map(int, input().split()))
result = 1
for mod in m:
	result = result * mod // gcd(result, mod)
good = 0
for i in range(result):
	for (mod, car) in zip(m, r):
		if i % mod == car:
			good += 1
			break
print(good / result)


n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))

def gcd(a, b):
	if a == 0:
		return b
	elif a > b:
		return gcd(a % b, b)
	else:
		return gcd(b % a, a)
d = 1
for i in range(n):
	d = d * m[i] // gcd(d, m[i])
c = 0
for j in range(1, d + 1):
	for i in range(n):
		if j % m[i] == r[i]:
			c += 1
			break
print(c / d)


def scrambled(lst1, lst2):
	count = 0
	for i in range(360360):
		flag = 0
		for (x, y) in zip(lst2, lst1):
			if i % y == x:
				flag = 1
				break
		if flag:
			count += 1
	return '{0:.6f}'.format(count / 360360)
N = int(input())
m = [int(j) for j in input().split()]
r = [int(z) for z in input().split()]
print(scrambled(m, r))


n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
cnt = 0
for i in range(720720):
	for j in range(n):
		if i % m[j] == r[j]:
			cnt += 1
			break
print(cnt / 720720)


n = int(input())
m = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
count = 0
for i in range(40000):
	for j in range(n):
		if i % m[j] == r[j]:
			count += 1
			break
print(count / 40000)


from functools import reduce

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	return x * y // gcd(x, y)
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
g = reduce(lambda x, y: lcm(x, y), m)
count = 0
for i in range(g):
	for j in range(n):
		if i % m[j] == r[j]:
			count += 1
			break
print(count / g)


a = 30030
n = int(input())
m = [int(_) for _ in input().split()]
r = [int(_) for _ in input().split()]
ans = 0
for i in range(a):
	for j in range(n):
		if i % m[j] == r[j]:
			ans += 1
			break
print(ans / a)


from fractions import gcd
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
tot = 1
for i in m:
	tot = tot * i // gcd(tot, i)
has = [0] * tot
for i in range(n):
	on = r[i]
	while on < tot:
		has[on] = 1
		on += m[i]
print(sum(has) / tot)


n = int(input())
m = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
counter = 0
num = 50000
for d in range(num):
	for i in range(n):
		if d % m[i] == r[i]:
			counter += 1
			break
frac = counter / num
print(frac)


N = int(input())
M = list(map(int, input().split()))
R = list(map(int, input().split()))

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)
s = 1
for m in M:
	s = lcm(s, m)
t = 0
for d in range(s):
	k = False
	for (i, m) in enumerate(M):
		r = R[i]
		if d % m == r:
			k = True
			break
	if k:
		t += 1
print(t / s)


n = int(input())
m = [int(q) for q in input().split()]
r = [int(q) for q in input().split()]
c = 0
for d in range(10 ** 5):
	for i in range(min(len(m), len(r))):
		if d % m[i] == r[i]:
			c += 1
			break
print(c / (10 ** 5 + 1))


n = int(input())
M = list(map(int, input().split()))
R = list(map(int, input().split()))
N = 720720
P = 0
for x in range(N):
	if any((x % M[i] == R[i] for i in range(n))):
		P += 1
print(P * 1.0 / N)


def nod(a, b):
	for i in range(min(a, b), 0, -1):
		if a % i == 0 and b % i == 0:
			return i

def nok(a, b):
	return a * b // nod(a, b)
n = int(input())
m = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
ans = 1
for i in range(n):
	ans = nok(ans, m[i])
x = 0
for d in range(ans):
	for i in range(n):
		if d % m[i] == r[i]:
			x += 1
			break
print(x / ans)


def gcd(a, b):
	if b:
		return gcd(b, a % b)
	else:
		return a

def lcm(A):
	m = A[0]
	for a in A[1:]:
		m = m * a // gcd(m, a)
	return m
n = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
m = lcm(A)
cnt = 0
for day in range(1, m + 1):
	flag = True
	for j in range(n):
		if day % A[j] == B[j]:
			flag = False
			break
	if flag == False:
		cnt += 1
print(cnt / m)


a = int(input())
d = 34209
p = 0
m = list(map(int, input().split()))
r = list(map(int, input().split()))
for i in range(34209):
	for j in range(a):
		if i % m[j] == r[j]:
			p += 1
			break
s = round(p / d, 4)
print(s)


n = int(input())
M = list(map(int, input().split()))
R = list(map(int, input().split()))

def nod(x, y):
	while x != 0 and y != 0:
		if x > y:
			x = x % y
		else:
			y = y % x
	return x + y
k = 1
for i in M:
	k = k * i // nod(k, i)
ans = 0
for D in range(k):
	for i in range(n):
		if D % M[i] == R[i]:
			ans += 1
			break
print(ans / k)


def gcd(a, b):
	if a == 0:
		return b
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
cap = 1
for val in m:
	cap = lcm(cap, val)
ans = 0
for day in range(cap):
	works = False
	for i in range(n):
		if day % m[i] == r[i]:
			works = True
			break
	if works:
		ans += 1
print(ans / cap)


import fractions
from functools import reduce
N = int(input())
M = list(map(int, input().split(' ')))
R = list(map(int, input().split(' ')))

def gcd(*numbers):
	return reduce(fractions.gcd, numbers)

def lcm(*numbers):

	def _lcm(a, b):
		return a * b // gcd(a, b)
	return reduce(_lcm, numbers, 1)
lcm_M = lcm(*M)
a = [any((d % M[i] == R[i] for i in range(N))) for d in range(lcm_M)]
print(a.count(True) / len(a))


from fractions import gcd
(n, m, r) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
lcm = m[0]
for mi in m:
	lcm = lcm * mi // gcd(lcm, mi)
print(sum((any((i % mj == rj for (mj, rj) in zip(m, r))) for i in range(lcm))) / lcm)


n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
count = 0
N = 100000
for D in range(N):
	for i in range(n):
		if D % m[i] == r[i]:
			count += 1
			break
print(count / N)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = 0
for i in range(1000000):
	for j in range(n):
		if i % a[j] == b[j]:
			ans += 1
			break
print(ans / 1000000)


__author__ = 'runekri3'
N = int(input())
M = list(map(int, input().split()))
R = list(map(int, input().split()))
total_days = 100000
days_you_washed = 0
for D in range(total_days):
	for i in range(N):
		if D % M[i] == R[i]:
			days_you_washed += 1
			break
print(days_you_washed / total_days)


n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
days = 0
for i in range(pow(2, 17)):
	for j in range(n):
		if i % m[j] == r[j]:
			days += 1
			break
print(days / pow(2, 17))


n = int(input())
M = list(map(int, input().split()))
R = list(map(int, input().split()))
t = 0
num = max(max(M), max(R)) * 10000
for d in range(num):
	for i in range(n):
		if d % M[i] == R[i]:
			t += 1
			break
print(t / num)


k = int(input())
q1 = list(map(int, input().split()))
q2 = list(map(int, input().split()))
z = 100000
ans = 0
for i in range(1, z + 1):
	for j in range(len(q1)):
		if i % q1[j] == q2[j]:
			ans += 1
			break
print(ans / z)


n = int(input())
mod = list(map(int, input().split()))
rem = list(map(int, input().split()))
cnt = 0
for d in range(360360):
	we = False
	for (r, m) in zip(rem, mod):
		if d % m == r:
			we = True
			break
	if we:
		cnt += 1
print(cnt / 360360)


def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		a %= b
		(a, b) = (b, a)
	return b

def gsd(a, b):
	return a * b // gcd(a, b)
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
x = m[0]
for i in range(1, n):
	x = gsd(x, m[i])
count = 0
for i in range(x):
	for j in range(n):
		if i % m[j] == r[j]:
			count += 1
			break
print(count / x)


def gcd(a, b):
	while b != 0:
		a %= b
		(a, b) = (b, a)
	return abs(a)

def lcm(a, b):
	return abs(a * b) // gcd(a, b)
n = int(input())
m = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
l = 1
for i in m:
	if i != 0:
		l = lcm(l, i)
c = 0
for d in range(l):
	f = False
	for i in range(n):
		if m[i] != 0 and d % m[i] == r[i]:
			f = True
			break
	if f:
		c += 1
print(c / l)


import time

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	while b != 0:
		while a >= b:
			a -= b
		(a, b) = (b, a)
	return a
n = int(input())
M = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]
start = time.time()
m = 1
for i in range(n):
	m = lcm(m, M[i])
a = [0 for i in range(m)]
for i in range(n):
	if R[i] >= M[i]:
		continue
	now = R[i] - 1
	if now < 0:
		now += M[i]
	while now < m:
		a[now] = 1
		now += M[i]
print(sum(a) / m)
finish = time.time()


Maxv = 720720
n = int(input())
s = 0
m = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
m.reverse()
m.append(0)
m.reverse()
r.reverse()
r.append(0)
r.reverse()
for i in range(1, Maxv + 1):
	for j in range(1, n + 1):
		if i % m[j] == r[j]:
			s += 1
			break
ans = 1.0 * s / Maxv
print('%.6lf' % ans)