Problem:

一般化うるう年

通常，西暦 x 年がうるう年か否かは以下のように定義されている．

x が 400 の倍数であれば，うるう年である．

そうでないとき，x が 100 の倍数であれば，うるう年ではない．

そうでないとき，x が 4 の倍数であれば，うるう年である．

そうでないとき，うるう年ではない．

これは次のように一般化できる．ある数列 A1, ..., An について，西暦 x 年が "一般化うるう年" であるか否かを以下のように定義する．

x が Ai の倍数であるような最小の i (1 ≤ i ≤ n) について，i が奇数であれば一般化うるう年であり，偶数であれば一般化うるう年ではない．

そのような i が存在しないとき，n が奇数であれば一般化うるう年ではなく，偶数であれば一般化うるう年である．

例えば A = [400, 100, 4] のとき，この A に対する一般化うるう年は通常のうるう年と等価になる．

数列 A1, ..., An と正の整数 l, r が与えられるので．l ≤ x ≤ r なる正の整数 x のうち，西暦 x 年が A に対する一般化うるう年であるような x の個数を答えよ．

Input

入力は最大で 50 個のデータセットからなる．各データセットは次の形式で表される．

n l r
A1
A2
...
An

整数 n は 1 ≤ n ≤ 50 を満たす．整数 l,r は1 ≤ l ≤ r ≤ 4000 を満たす．各 i に対し整数 Ai は 1 ≤ Ai ≤ 4000 を満たす．

入力の終わりは 3 つのゼロからなる行で表される．

Output

各データセットについて，答えを 1 行で出力せよ．

Sample Input

3 1988 2014
400
100
4
1 1000 1999
1
2 1111 3333
2
2
6 2000 3000
5
7
11
9
3
13
0 0 0

Output for the Sample Input

7
1000
2223
785



Sample input:
3 1988 2014
400
100
4
1 1000 1999
1
2 1111 3333
2
2
6 2000 3000
5
7
11
9
3
13
0 0 0


Sample output:
7
1000
2223
785

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = [0]*a[0]
su = 0
s = 0
while sum(a) != 0:
	b = [0] * a[0]
	for i in range(a[0]):
		b[i] = int(input())

	for i in range(a[1],a[2]+1):
		for j in range(a[0]):
			if i % b[j] == 0:
				if j % 2 == 0:
					s += 1
					su += 1
					break
		if s == 0:
			if a[0] % 2 == 0:
				su += 1

		s = 0

	print(su)
	su = 0

	a = list(map(int,input().split()))

Submission status: Accepted

Solution code:
while True:
    n, r, l = map(int, input().split())
    if n == 0:
        break
    else:
        a = []
        for i in range(n):
            a.append(int(input()))
        a.append(1)
        count = 0
        for i in range(r, l + 1):
            for j in range(n + 1):
                if i % a[j] == 0:
                    if j % 2 == 0:
                        count += 1
                    break
        print(count)

Submission status: Accepted

Solution code:
# AOJ 2882: Generalized Leap Years
# Python3 2018.7.10 bal4u

while True:
	n, l, r = map(int, input().split())
	if n == 0: break
	A = [int(input()) for i in range(n)][::-1]
	y = [0]*(r+1)
	v = 2 - (n&1)	# v = 1 if n is odd
	for a in A:
		for i in range(a, r+1, a): y[i] = v
		v = 3-v
	ans = k = 0
	for i in range(l, r+1):
		if y[i] == 0: k += 1
		elif y[i] == 1: ans += 1
	if n & 1 == 0: ans += k
	print(ans)

Submission status: Accepted

Solution code:
while True:
    n, l, r = map(int, input().split())
    if (n | l | r) == 0:
        break

    A = []

    for i in range(n):
        A.append(int(input()))

    ans = 0

    for y in range(l, r + 1):

        a = 0

        for i in range(n):
            if y % A[i] == 0:
                a = i + 1
                break

        if a != 0 and a % 2 == 1:
            ans += 1

        if a == 0 and n % 2 == 0:
            ans += 1

    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n,l,r=map(int, input().split())
    if n==0:
        break
    a = []
    for i in range(n):
        a.append(int(input()))
    c = 0
    for j in range(l, r+1):
        for i in range(n):
            if j%a[i]==0:
                if i%2==1:
                    break
                else:
                    c += 1
                    break
            if i==n-1 and n%2==0:
                c += 1
    print(c)

Submission status: Accepted

Solution code:
while(True):
	n,l,r = map(int, input().split())
	if (n+l+r)==0:break
	a = list(int(input()) for i in range(n))
	count = 0
	for year in range(l,r+1):
		var = n
		for i in range(n):
			if year%a[i]==0:
				var = i
				break
		if var%2==0:
			count += 1
	print(count)

Submission status: Accepted

Solution code:
while True:
    n, l, r = map(int, input().split())
    if n == 0: break
    A = [int(input()) for i in range(n)][::-1]
    y = [0]*(r+1)
    v = 2 - (n&1)   # v = 1 if n is odd
    for a in A:
        for i in range(a, r+1, a): y[i] = v
        v = 3-v
    ans = k = 0
    for i in range(l, r+1):
        if y[i] == 0: k += 1
        elif y[i] == 1: ans += 1
    if n & 1 == 0: ans += k
    print(ans)

Submission status: Accepted

Solution code:
import math

while 1:
    n, l, r = map(int, input().split())
    if (n, l, r) == (0, 0, 0): break
    aa = [int(input()) for _ in range(n)]
    koho = set([i for i in range(l, r + 1)])
    baisu = set()
    uru = set()
    for i, a in enumerate(aa):
        start = math.ceil(l / a) * a
        for k in range(start, r + 1, a):
            baisu.add(k)
        # iが奇数の時＝うるう
        if not i % 2:
            uru |= koho & baisu
        koho -= baisu
    if not n % 2:
        uru |= koho
    print(len(uru))

Submission status: Accepted

Solution code:
import math
for i in range(50):
	n,l,r=map(int,input().split())
	if n==0 and l==0 and r==0:
		break
	else:
		a=[]
		for ii in range(n):
			a.append(int(input()))
		ans=0
		

		for k in range(l,r+1):

			for s in range(math.ceil(n/2)):
				if k%a[2*s]==0:
					ans+=1
					break
				elif 2*s+1==n :
					break
				elif k%a[2*s+1]==0:
					break
				elif s==math.ceil(n/2)-1 and n%2==0:
					ans+=1
					break
				else:
					continue

					


		print(ans)

Submission status: Accepted

Solution code:
while 1:
    n, l, r = map(int, input().split())
    if n == 0: break

    a = []
    for i in range(n):
        a.append(int(input()))

    gusu = False
    if len(a) % 2 == 0: gusu = True

    count = 0
    for x in range(l, r + 1):
        for i in range(len(a)):
            comp = a[i]
            if x % comp == 0:
                if i % 2 == 0:
                    count += 1
                    break
                else: break
        else:
            if gusu: count += 1
    print(count)

Submission status: Accepted

Solution code:

while True:
    

    n,l,r = map(int,input().split())

    ans = 0

    if n == 0 and l == 0 and r == 0:
        break

    A = []

    for i in range(n):

        a = int(input())

        A.append(a)


    for x in range(r-l+1):

        x += l

        #print (x)

        for i in range(len(A)):

            
            flag = True

            if x % A[i] == 0:

                if i % 2 == 0:
                    ans += 1
                   # print (x,"は",A[i],i)


                #print (x,"はだめ",A[i],i)
                flag = False
                break

        if flag and len(A) % 2 == 0:

            #print (x , "x")

            ans += 1


    print (ans)

Submission status: Accepted

Solution code:
while True:
    n,l,r = map(int, input().split())
    if n==0 and l==0 and r==0:
        break
    a = [0]*n
    cnt = 0
    for i in range(n):
        a[i]=int(input())
        # aのリスト完成
    for x in range(l,r+1):
        for i in range(1,n+1):
            if x%a[i-1]==0:
                if i%2==1:
                    cnt += 1
                break
            if i==n and n%2==0:
                cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
while True:
    n, l, r = map(int, input().split())
    if n+l+r == 0:
        break
    As = [int(input()) for _ in range(n)]
    ans = 0
    for jj in range(l, r+1):
        flag = False
        for i, a in enumerate(As):
            if flag:
                break
            if jj % a == 0:
                if (i+1) % 2 == 1:
                    flag = True
                    ans += 1
                    break
                else:
                    flag = True
        if flag:
            continue
        else:
            if n % 2 == 0:
                ans += 1

    print(ans)

Submission status: Accepted

Solution code:

while True:
	n,l,r = map(int,input().split())
	if n == 0:
		break
	a = []
	for _ in range(n):
		a.append(int(input()))
	a.append(1)
	ans = 0
	for i in range(l,r+1):
		for j,aa in enumerate(a):
			if i % aa == 0:
				if j % 2 == 0:
					ans += 1
				break
	print(ans)

Submission status: Accepted

Solution code:
ans_list = []

while True:
    n,l,r = map(int,input().split())
    if (n,l,r) == (0,0,0):
        break
    A = [int(input()) for _ in range(n)]
    cnt = 0
    for x in range(l,r+1):
        for i,a in enumerate(A,1):
            if x % a == 0:
                if i % 2 == 1:
                    cnt += 1
                break
            if i == n:
                if n % 2 == 0:
                    cnt += 1
    ans_list.append(cnt)

for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
def solve(n ,l, r, A):
    res = 0
    for x in range(l, r+1):
        for i in range(n):
            if (not x%A[i]) :
                res += 0 if (i&1) else 1
                break
        else:
            res += 0 if (n&1) else 1
    return res



def main():
    ans = []
    while True:
        n, l, r = map(int, input().split())
        if (not n) and (not l) and (not r):
            break
        A = [int(input()) for i in range(n)]
        ans.append(solve(n,l,r,A))
    for i in ans:
        print(i)


main()

Submission status: Accepted

Solution code:
while True:
    n, l, r = map(int, input().split())
    if n == l == r == 0:
        break
    A = [int(input()) for i in range(n)]
    ans = 0
    for x in range(l, r+1):
        for i in range(n):
            if x % A[i] == 0:
                if i % 2 == 0:
                    ans += 1
                break
            elif i == (n-1):
                if n % 2 == 0:
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
"一般化うるう年"
while True:
    n, l, r = map(int, input().split())  # 数列の要素の個数はn個, lからrまでのxを試す
    if n == 0:
        break
    A = [int(input()) for _ in range(n)]

    ans = 0
    for x in range(l, r+1):
        flag = True
        for i in range(n):
            if x%A[i] == 0 and (i+1)%2 == 1:
                ans += 1
                flag = False
                break
            elif x%A[i] == 0 and (i+1)%2 == 0:
                flag = False
                break

        if flag:
            if n%2 == 0:
                ans += 1

    print(ans)

Submission status: Accepted

Solution code:
ans = []

while True:
    n, l, r = map(int, input().split())
    if n + l + r == 0:
        break

    a = []
    for i in range(n):
        a.append(int(input()))
   
    cnt = 0
    for x in range(l, r + 1):
        
        for j in range(n):
            if x % a[j] == 0:
                if (j + 1) % 2 == 1:
                    cnt += 1
                break
            elif j == (n - 1):
                if n % 2 == 0:
                    cnt += 1
                 
    ans.append(cnt)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
while True:
  n, l, r = map(int, input().split())
  if n == 0 and l == 0 and r == 0:
    break
  else:
    a = [0 for i in range(n)]
    for i in range(n):
      aa = int(input())
      a[i] = aa
    cnt = 0
    for x in range(l, r + 1):
      flag = False
      for i in range(n):
        if x % a[i] == 0:
          flag = True
          break
      if (i+1) % 2 == 1 and flag == True:
        cnt += 1
      elif flag == False:
        if n % 2 == 0:
          cnt += 1
  print(cnt)

Submission status: Accepted

Solution code:
while True:
    n, l, r = map(int, input().split())
    if n == 0:
        break
    A = [int(input()) for _ in range(n)]

    ans = 0
    for x in range(l, r + 1):
        checked = False
        for i, a in enumerate(A):
            if x % a == 0:
                ans += (i % 2 == 0)
                checked = True
                break
        if not checked and n % 2 == 0:
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n,l,r=map(int,input().split())
    if n==l==r==0:break
    a=[]
    for i in range(n):
        a.append(int(input()))
    ans=0
    a.append(1)
    for i in range(l,r+1):
        for j in range(n+1):
            if i%a[j]==0:
                if j%2==0:ans+=1
                break
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n, l, r = map(int, input().split())
    if n == 0:
        break

    a = []
    for i in range(n):
        a.append(int(input()))
    a.append(1)
    cnt = 0
    for i in range(l, r+1):
        for j in range(n+1):
            if i % a[j] == 0:
                if j % 2 == 0:
                    cnt += 1
                break
    print(cnt)

Submission status: Accepted

Solution code:
while 1:
    n, l, r = map(int, input().split())
    if n == 0:
        break

    data = []
    for _ in range(n):
        data.append(int(input()))

    cnt = 0
    for i in range(l, r+1):
        for j, d in enumerate(data):
            if i % d == 0:
                if j % 2 == 0:
                    cnt += 1
                break
        else:
            if n % 2 == 0:
                cnt += 1

    print(cnt)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n,l,r):
        a = [I() for _ in range(n)]
        c = 0
        for t in range(l,r+1):
            k = -1
            for i in range(n):
                if t % a[i] == 0:
                    k = i
                    break
            if k < 0:
                k = n
            if k % 2 == 0:
                c += 1

        return c

    while 1:
        n,m,l = LI()
        if n == 0:
            break
        rr.append(f(n,m,l))

    return '\n'.join(map(str, rr))


print(main())

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
b = []
su = 0
s = 0
for i in range(a[0]):
	b.append(int(input()))

for i in range(a[1],a[2]+1):
	for j in range(a[0]):
		if a % b[j] == 0:
			su += 1
			if(j % 2 == 0):
				s += 1
				break
	if su == 0:
		if a[0] % 2 == 0:
			s += 1
	su = 0

print(s)