Under construction

Still being built. Things may change

Generalized Leap Year

Interview

Time limit8sMemory limit512 MB

Summary
For each test case, count integers x in [l, r] that satisfy a generalized leap year rule defined by a list of divisors A.
Level

Medium4 of 10

Topics
Implementation, Brute force, Math, Number theory
Solved
No attempts yet

Problem

Normally, whether year xx in the Common Era is a leap year is defined as follows.

  1. If xx is a multiple of 400, it is a leap year.
  2. Otherwise, if xx is a multiple of 100, it is not a leap year.
  3. Otherwise, if xx is a multiple of 4, it is a leap year.
  4. Otherwise, it is not a leap year.

This can be generalized as follows. Given a sequence A1,…,AnA_1, \dots, A_n, whether year xx in the Common Era is a "generalized leap year" is defined as follows.

  1. For the smallest ii (1≤i≤n1 \le i \le n) such that xx is a multiple of AiA_i, if ii is odd then it is a generalized leap year, and if ii is even then it is not.
  2. If no such ii exists, then if nn is odd it is not a generalized leap year, and if nn is even it is a generalized leap year.

For example, when A=[400,100,4]A = [400, 100, 4], the generalized leap years for this AA are the same as ordinary leap years.

Given a sequence A1,…,AnA_1, \dots, A_n and positive integers l,rl, r, find the number of positive integers xx with l≤x≤rl \le x \le r such that year xx in the Common Era is a generalized leap year for AA.

Input

The input consists of at most 50 data sets. Each data set has the following format.

n l r
A1
A2
...
An

The integer nn satisfies 1≤n≤501 \le n \le 50. The integers l,rl, r satisfy 1≤l≤r≤40001 \le l \le r \le 4000. For each ii, the integer AiA_i satisfies 1≤Ai≤40001 \le A_i \le 4000.

The end of the input is marked by a line of three zeros.

Output

For each data set, print the answer on one line.

Examples1

  1. Example 1

    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
    
    Expected output
    7
    1000
    2223
    785