program eight;
var
a:array[1..15]of longint;
p,ans,z,d:int64;
t,b,c,n,i:longint;
jilu:array[1..15]of integer;
procedure gcd(a,b:int64);
begin
if b=0 then
begin
d:=a;
exit
end
else
gcd(b,a mod b)
end;
procedure find(x:longint);
begin
if x=n+1 then
begin
p:=8;
t:=0;
for i:=1 to n do
begin
if jilu[i]=1 then
begin
inc(t);
gcd(p,a[i]);
p:=p*a[i]div d
end
end;
if t=0 then
exit;
if t mod 2 =1 then
begin
z:=z+c div p-(b-1)div p
end
else
begin
z:=z-(c div p-(b-1)div p)
end
end
else
begin
jilu[x]:=1;
find(x+1);
jilu[x]:=0;
find(x+1)
end
end;
begin
assign (input,'eight.in');
reset (input);
assign (output,'eight.out');
rewrite (output);
readln(n);
for i:=1 to n do
read (a[i]);
readln(b,c);
ans:=c div 8-(b-1)div 8;
z:=0;
find(1);
ans:=ans-z;
writeln (ans);
close (input);
close (output)
end.