Problem p00265 - Generation 1

Orig Description

Modulo Query
You are given N cards, each containing a different natural number (1 to 300000). When you are asked a question, you should answer the maximum remainder obtained when dividing the number on the card you have by the number I said.
For example, suppose you have three cards with numbers 9, 3, and 8. If I say "4", find the remainder when you divide 9, 3, and 8 by 4. The remainders are 1, 3, and 0, respectively, but the largest remainder is 3, so the correct answer is 3.
Now, let's get started. What? It's difficult if there are too many cards? Well, that's true. Then, let's use a computer to find the maximum remainder. Please create a program that finds the largest remainder among the remainders obtained by dividing the numbers on the cards by the number asked. Note that questions can be asked multiple times, but the same number will not be asked twice.
Input
The input consists of a single data set in the following format:
N Q
c1 c2 ... cN
q1
q2
:
qQ
The first line contains the number of cards N (2 ≤ N ≤ 300000) and the number of questions Q (2 ≤ Q ≤ 100000) separated by a single space. The second line contains the numbers ci (1 ≤ ci ≤ 300000) written on the cards separated by a single space. The next Q lines contain the numbers qi (1 ≤ qi ≤ 300000) asked as questions.
Output
Output the maximum remainder for each question on a separate line.
Sample Input
3 3
9 3 8
4
6
5
Sample Output
3
3
4

Extracted Specification

### Canonicalized Input Description:

An integer N (2 ≤ N ≤ 300000), representing some quantity or size.
An integer Q (2 ≤ Q ≤ 100000), representing some other quantity or size.
A list of integers A of size N, where each integer is between 1 and 300000.
A list of integers B of size Q, where each integer is between 1 and 300000.

### Example Input:

```
3 3
9 3 8
4
6
5
```

### Function Signature:
Write a function f(N, Q, A, B) that takes in the input.
def f(N: int, Q: int, A: List[int], B: List[int]):
    ''' 
    N: an integer
    Q: an integer
    A: a list of integers
    B: a list of integers
    '''

Test Case Generator

Sure! Here is a test case generator for the problem statement "Modulo Query":

```python
import random

def tcgen():
    # Generate N and Q within the specified limits
    N = random.randint(2, 300000)
    Q = random.randint(2, 100000)
    
    # Generate N unique card numbers each between 1 and 300000
    cards = random.sample(range(1, 300001), N)
    
    # Generate Q questions, each between 1 and 300000
    questions = [random.randint(1, 300000) for _ in range(Q)]
    
    return N, Q, cards, questions

# Example usage of the test case generator
if __name__ == "__main__":
    N, Q, cards, questions = tcgen()

    # Print the generated test case
    print(N, Q)
    print(" ".join(map(str, cards)))
    for q in questions:
        print(q)
```

### Explanation:
1. **N and Q Generation**:
   - `N` is chosen randomly between 2 and 300000.
   - `Q` is chosen randomly between 2 and 100000.

2. **Cards Generation**:
   - `cards` is a list of `N` unique integers between 1 and 300000. We use `random.sample` to ensure all numbers are unique.

3. **Questions Generation**:
   - `questions` is a list of `Q` integers, each randomly chosen between 1 and 300000.

### Example Output:
Running the generator might produce an output like:

```
5 3
105 204 305 102 509
4
7
3
```

This will give you a test case where:
- `N = 5` (number of cards)
- `Q = 3` (number of questions)
- The cards have numbers `[105, 204, 305, 102, 509]`
- The questions are `4`, `7`, and `3`

### Note:
- You can run the provided code multiple times to generate new test cases as needed.
- The generator ensures that the constraints given in the problem statement are respected.

Extract Arguments

def extract_arguments(fh):
    N, Q = map(int, fh.readline().strip().split())
    cards = list(map(int, fh.readline().strip().split()))
    queries = [int(fh.readline().strip()) for _ in range(Q)]
    return N, Q, cards, queries

# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh:
#         N, Q, cards, queries = extract_arguments(fh)
#         f(N, Q, cards, queries)