Generalized Leap Year
InterviewTime limit8sMemory limit512 MB
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 in the Common Era is a leap year is defined as follows.
- If is a multiple of 400, it is a leap year.
- Otherwise, if is a multiple of 100, it is not a leap year.
- Otherwise, if is a multiple of 4, it is a leap year.
- Otherwise, it is not a leap year.
This can be generalized as follows. Given a sequence , whether year in the Common Era is a "generalized leap year" is defined as follows.
- For the smallest () such that is a multiple of , if is odd then it is a generalized leap year, and if is even then it is not.
- If no such exists, then if is odd it is not a generalized leap year, and if is even it is a generalized leap year.
For example, when , the generalized leap years for this are the same as ordinary leap years.
Given a sequence and positive integers , find the number of positive integers with such that year in the Common Era is a generalized leap year for .
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 satisfies . The integers satisfy . For each , the integer satisfies .
The end of the input is marked by a line of three zeros.
Output
For each data set, print the answer on one line.