#P17899. [ICPC 2026 Nanchang I] Little Z's Function
[ICPC 2026 Nanchang I] Little Z's Function
Problem Description
Little Z was obsessed with number-theoretic functions such as Euler's totient function (Note: denotes the number of positive integers not exceeding that are coprime to .) back in high school.
One day, Little Z decides to play a game with his robotic friend. First, Little Z gives a permutation (Note: A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).) of length . Then he asks his friend multiple queries. For a given interval (), find the maximum value of where .
Formally, for each query with two integers , you need to compute:
$$\max_{l \le i < j \le r} \varphi ( p_i \times p_j )$$Little Z has solved exactly queries. Please help him compute the remaining queries.
Input Format
The first line contains a positive integer () --- the length of the permutation.
The second line contains distinct integers () --- the given permutation .
The third line contains a positive integer () --- the number of queries.
Each of the next lines contains two integers and () --- the endpoints of the -th query.
Output Format
For each query, output a single integer --- the maximum value.
6
3 2 5 4 1 6
8
4 5
2 6
3 5
2 3
3 4
1 5
4 5
2 6
2
8
8
4
8
8
2
8