# Remove Numbers Codechef Solution

### We Are Discuss About CODECHEF SOLUTION

Remove Numbers Codechef Solution

## Problem

Two players are playing a game. They are given an array A_1, A_2, \ldots, A_N as well as an array B_1, B_2, \ldots, B_M.

The game consists of M rounds. Players are participating in rounds alternatively. During the i-th round (for i from 1 to M) the corresponding player (first player, if i is odd, and second if i is even) has to do exactly one of the following:

• remove all elements from the array A that are divisible by B_i,
• remove all elements from the array A that are not divisible by B_i.

The first player wants to minimize the sum of the remaining elements in the array A after all M rounds, and the second wants to maximize it. Find the sum of the remaining elements in the array A after all M rounds if both players are playing optimally.

### Input Format

The first line contains two integers NM  the length of the array A and the number of rounds in the game.

The second line contains N integers A_1, A_2, \ldots, A_N  the elements of the array A.

The third line contains M integers B_1, B_2, \ldots, B_M  the elements of the array B.

### Output Format

Output a single integer  the sum of the remaining elements of the array A after all M rounds if both players are playing optimally.

### Constraints

• 1 \leq N \leq 2 \cdot 10^4
• 1 \leq M \leq 2 \cdot 10^5
• -4 \cdot 10^{14} \leq A_i \leq 4 \cdot 10^{14}
• 1 \leq B_i \leq 4 \cdot 10^{14}

• Subtask 1 (22 points): B_{i + 1} \bmod B_i = 0 (1 \leq i \lt M)
• Subtask 2 (24 points): 1 \leq M \leq 20
• Subtask 3 (28 points): 1 \leq M \leq 100

### Sample 1:

Input

Output

6 2
2 2 5 2 2 7
2 5
7

### Explanation:

In the sample, one possible flow of the game is the following:

• Round 1: first player removes from A all elements divisible by 2A becomes (5, 7).
• Round 2: second player removes from A all elements divisible by 5A becomes (7). If he had removed from A all elements not divisible by 5A would become (5), which has a smaller sum of elements and therefore is not desirable for the second player.

## Remove Numbers Codechef Solution

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here JOIN NOW