시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 256 MB418617.647%

문제

You are given a sequence $a_1, a_2, \ldots, a_n$ consisting of positive integers. You have to answer $q$ queries. A query is defined by a triplet of numbers $(l, r, x)$. For each query, you have to find the largest $p$ such that $l \leq p \leq r$ and $a_p$ is coprime with $x$, or determine that there is no such $p$.

입력

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

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 100\,000$).

The next $m$ lines contain queries. The $i$-th of these lines contains three integers $l_i$, $r_i$ and $x_i$ ($1 \le l_i \le r_i \le n$, $1 \le x \le 100\,000$).

출력

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

예제 입력 1

5 4
1 2 3 4 6
1 5 2
1 1 1
4 5 2
3 5 3

예제 출력 1

3
1
-1
4