#C2154. Largest Prime Query

    ID: 45439 Type: Default 1000ms 256MiB

Largest Prime Query

Largest Prime Query

You are given an array of integers and a list of queries. For each query, your task is to determine the largest prime number in the array that is less than or equal to the query value. If there is no prime number in the array that satisfies the condition, output -1.

Formally, given an array arr of N integers and Q queries, for each query x find the maximum prime number p from arr such that

[ p \le x ]

If no such p exists, output -1.

inputFormat

The first line contains two space-separated integers \(N\) and \(Q\) representing the number of elements in the array and the number of queries, respectively.

The second line contains \(N\) space-separated integers representing the elements of the array.

The third line contains \(Q\) space-separated integers representing the query values.

outputFormat

Output a single line with \(Q\) space-separated integers. Each integer should be the largest prime number from the array that is less than or equal to the corresponding query value. If no such prime exists for a query, output -1 for that query.

## sample
6 4
3 7 11 13 17 19
20 15 10 5
19 13 7 3