Recent brush algorithm problem encountered a problem:
Give a sequence of length n {a[1], a[2], a[3], ..., A[n]}, and M-group inquiry (L[i], r[i], k[i]).
The number of occurrences of the sequence subscript interval in [L[i], R[i]] coprime (Greatest common divisor 1) is in this interval. Input Description:
The first line, two positive integers n, m (1≤n, m≤50000). The second line, n positive integers a[i] (1≤a[i]≤n) describes the sequence. Next m line, three positive integers per line l[i], R[i], K[i] (1≤l[i]≤r[i]≤n, 1≤k[i]≤n), describes a query.
Output Description:
Output m line, that is, the answer to each query.
At first my idea was to just press test instructions to do it, but the final display time was too complicated to go through, because it was the complexity of O (MN).
So on Google the solution of the great God, so search out a great algorithm-mo team algorithm, listen to the name is very powerful look! Altogether is a Chinese invented = =. Then studied in detail a wave:
MO team algorithm Mo ' s algorithm