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

Difficulty: interview

Starter code:

Solutions:
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)


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):
    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()))
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)


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)

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 = [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)

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)

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)


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 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)


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=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 = 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 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)



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()


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)

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)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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()
#print(finish - start)


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)

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

count = 0.0
for i in range(100000):
    for j in range(len(m)):
        if i % m[j] == r[j]:
            count += 1
            break
print(count / 100000.0)



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)

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)

__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)