Gats's Universal Necklaces
Gats is preparing necklaces from several designs. Design contains two strings with and ordinary beads, together with a connector containing beads.
For a chosen positive integer target size , Gats removes as many complete groups of beads as possible from each ordinary string. The two strings therefore leave and beads.
Design closes perfectly at size exactly when
A size is universal if every one of the designs closes perfectly at that size.
For each of queries, determine how many universal integer sizes belong to the given inclusive interval.
Input
The first line contains two integers and (, ), the number of necklace designs and the number of queries.
Output
For each query , print one integer: the number of universal positive integer sizes satisfying .
Samples
Sample 1
Input
2 3 8 5 2 3 10 2 1 5 6 14 5 20
Output
1 0 2
The universal necklace sizes are and . The three query intervals contain one, zero, and two of these sizes, respectively.
Sample 2
Input
1 2 0 0 7 1 6 7 7
Output
0 1
With no ordinary beads on either string, the connector closes the design only when the target size is .