#GL0000157. Mô-đun lớn nhất để các phần tử đồng dư (Maximum modulo equality)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mô-đun lớn nhất để các phần tử đồng dư (Maximum modulo equality)
Maximum modulo equality
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of positive integers, answer queries on inclusive subarrays . For each query, find the largest positive integer such that all have the same remainder modulo .
If is unbounded because all values in the segment are equal, print 0 by convention. This includes ranges of length one. Queries do not modify the array.
Input
The first line contains . The second line contains the array values. Each of the next lines contains with .
Output
For each query print the greatest admissible modulus, or 0 if it is unbounded.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5 5
5 14 2 6 3
4 5
1 4
2 4
3 5
1 1
Output
3
1
4
1
0
Explanation
For , the values have the same residue modulo , the largest feasible modulus. For , share residue modulo . Queries and have answer . A single-element segment has an unbounded modulus and therefore outputs 0.