Coprime Queries

아직 제출이 없습니다시간 제한3초메모리 제한256 MB

문제

You are given a sequence a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n consisting of positive integers. You have to answer qq queries. A query is defined by a triplet of numbers (l,r,x)(l, r, x). For each query, you have to find the largest pp such that lprl \leq p \leq r and a_pa\_p is coprime with xx, or determine that there is no such pp.

입력

The first line of the input contains two integers nn and qq (1n,q100,000)1 \leq n, q \leq 100\\,000).

The second line contains nn integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n (1a_i100,0001 \le a\_i \le 100\\,000).

The next mm lines contain queries. The ii-th of these lines contains three integers l_il\_i, r_ir\_i and x_ix\_i (1l_ir_in1 \le l\_i \le r\_i \le n, 1x100,0001 \le x \le 100\\,000).

출력

For each query, output the answer to it on a separate line.