Minimum factor

0

0 votes
Very-Easy
Problem

You are given an array of n numbers. Now there are m queries asked. Each query contains an integer INDEX denoting an index of array (1- based indexing). Let the number at this index be a[i]. Now your task is to find the minimum proper factor of a[i] that is present in the array.

NOTE - For a number A, 1 and A are not proper factors of A.

INPUT

First line of input contains n, m, the number of elements in the array and the number of queries respectively. The next line contains n space separated integers. The next m lines contains a single integer INDEX denoting an index in the array.

OUTPUT

Print the minimum proper factor for each query in a new line. In case the proper factor of a number is not present in the array or it does not exist, print "-1" (without quotes).

CONSTRAINTS

1n,m106

0ai106

1INDEXn

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Editor Image

?