Mojtaba's Array and Arpa's Queries

4.2

12 votes
Advanced Data Structures, Data Structures, Easy, Fenwick tree
Problem

Mojtba has an array a with n elements and an integer k. Arpa has q query in type [L,R], for i-th query print the length of the shortest segment [x,y][Li,Ri], such that k|yj=xaj.

Input Format

The first line of input will contain three integers, n,k,q (1n,q5105, 1k109).

Next line will contain n integers a1,a2,a3,...,an - integers of the array a (1ai109).

In i-th line of the next q lines, two integers given, Li,Ri (1LiRin).

Output Format

For each query print the length of the shortest segment [x,y][L,R], such that k|yi=xai. If there is no segment satisfying the condition, print 1.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In the first query, [2,7] the segment [3,4] belongs to it and has the product 6 which is divisible by k=6. Its size is 2 so the answer for that query is 2.

Editor Image

?