logo AlgoBeat OnlineJudge
登录 注册

#215798. [JAG 2024 Summer Camp #2] Max Sum of GCD

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

For a sequence of positive integers where , let be the answer to the following problem:

  • Among the positive integers , paint at least one and at most of them red, and paint the rest blue. Let be the greatest common divisor (GCD) of the integers painted red, and be the GCD of the integers painted blue. Find the maximum possible value of .

You are given a sequence of positive integers . You will also be given queries. For each query, you will be given two integers and such that . For each query, let , and find .

输入格式

The input is given in the following format:

  • for all
  • for all

输出格式

Print lines. On the -th line (), output the answer to the -th query.

样例

样例输入 1

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

样例输出 1

7
9
7