Problem p00265 - Generation 3

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

An integer N (2 ≤ N ≤ 300000), representing some quantity or size.
An integer Q (2 ≤ Q ≤ 100000), representing some 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

Certainly! A test case generator for the "Modulo Query" problem would need to generate random values for the number of cards \(N\) and the number of questions \(Q\), followed by generating random natural numbers for the cards and the questions. Here’s a Python function to generate such test cases:

```python
import random

def tcgen():
    # Number of cards N (2 ≤ N ≤ 300000)
    N = random.randint(2, 300000)
    
    # Number of questions Q (2 ≤ Q ≤ 100000)
    Q = random.randint(2, 100000)
    
    # List of card values c1 to cN (1 ≤ ci ≤ 300000)
    cards = [random.randint(1, 300000) for _ in range(N)]
    
    # List of question values q1 to qQ (1 ≤ qi ≤ 300000)
    questions = []
    question_set = set()  # to ensure no duplicate questions
    
    while len(questions) < Q:
        q = random.randint(1, 300000)
        if q not in question_set:
            questions.append(q)
            question_set.add(q)
    
    return N, Q, cards, questions

# Example usage
N, Q, cards, questions = tcgen()
print(N, Q)
print(" ".join(map(str, cards)))
for question in questions:
    print(question)
```

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

2. **Cards Generation**:
   - `cards` is a list of \(N\) random integers, each between 1 and 300000.

3. **Questions Generation**:
   - `questions` is a list of \(Q\) unique random integers, each between 1 and 300000. We use a set to ensure there are no duplicate questions.

This function outputs the generated test case in the format required for the "Modulo Query" problem. You can run the generator multiple times to create different test cases for thorough testing of your solution.

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)