CF2167D.Yet Another Array Problem

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an integer nn and an array aa of length nn.

Find the smallest integer xx (2≤x≤10182 \le x \le 10^{18}) such that there exists an index ii (1≤i≤n1 \le i \le n) with gcd⁡\gcd∗^{\text{∗}}(ai,x)=1(a_i, x) = 1. If no such xx exists within the range [2,1018][2,10^{18}], output −1-1.

∗^{\text{∗}}gcd⁡(x,y)\gcd(x, y) denotes the greatest common divisor (GCD) of integers xx and yy.

给你一个整数 nn 和一个长度为 nn 的数组 aa。

请找出最小的整数 xx(满足 2≤x≤10182 \le x \le 10^{18}),使得存在某个下标 ii(满足 1≤i≤n1 \le i \le n),有 gcd⁡\gcd∗^{\text{∗}}(ai,x)=1(a_i, x) = 1。若在区间 [2,1018][2,10^{18}] 内不存在这样的 xx,则输出 −1-1。

∗^{\text{∗}}gcd⁡(x,y)\gcd(x, y) 表示整数 xx 与 yy 的最大公约数(GCD)。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each of the following tt test cases consists of two lines:

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^{5}) — the length of the array.

The second line contains nn space-separated integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤10181 \le a_i \le 10^{18}).

It is guaranteed that the total sum of nn across all test cases does not exceed 10510^{5}.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

接下来的 tt 个测试用例,每个测试用例包含两行:

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^{5})—— 数组的长度。

第二行包含 nn 个以空格分隔的整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤10181 \le a_i \le 10^{18})。

保证所有测试用例中 nn 的总和不超过 10510^{5}。

输出格式

For each test case, output a single integer: the smallest xx (2≤x≤10182 \le x \le 10^{18}) such that there exists an index ii with gcd⁡(ai,x)=1\gcd(a_i, x) = 1. If there is no such xx in the range [2,1018][2,10^{18}], print −1-1.

对于每个测试用例,输出一个整数:满足存在某个下标 ii 使得 gcd⁡(ai,x)=1\gcd(a_i, x) = 1 的最小 xx(其中 2≤x≤10182 \le x \le 10^{18})。若在区间 [2,1018][2,10^{18}] 内不存在这样的 xx,则输出 −1-1。

输入输出样例

  • 输入#1

    4
    1
    1
    4
    6 6 12 12
    3
    24 120 210
    4
    2 4 6 10

    输出#1

    2
    5
    5
    3

说明/提示

In the first test case, gcd⁡(2,1)=1\gcd(2,1)=1, which is the smallest number satisfying the condition.

In the second test case:

  • gcd⁡(2,6)=2\gcd(2,6)=2, gcd⁡(2,12)=2\gcd(2,12)=2, so 22 cannot be the answer.
  • gcd⁡(3,6)=3\gcd(3,6)=3, gcd⁡(3,12)=3\gcd(3,12)=3, so 33 cannot be the answer.
  • gcd⁡(4,6)=2\gcd(4,6)=2, gcd⁡(4,12)=4\gcd(4,12)=4, so 44 cannot be the answer.
  • gcd⁡(5,6)=1\gcd(5,6)=1, so the answer is 55.

In the third test case:

  • gcd⁡(2,24)=2\gcd(2,24)=2, gcd⁡(2,120)=2\gcd(2,120)=2, gcd⁡(2,210)=2\gcd(2,210)=2, so 22 cannot be the answer.
  • gcd⁡(3,24)=3\gcd(3,24)=3, gcd⁡(3,120)=3\gcd(3,120)=3, gcd⁡(3,210)=3\gcd(3,210)=3, so 33 cannot be the answer.
  • gcd⁡(4,24)=4\gcd(4,24)=4, gcd⁡(4,120)=4\gcd(4,120)=4, gcd⁡(4,210)=2\gcd(4,210)=2, so 44 cannot be the answer.
  • gcd⁡(5,24)=1\gcd(5,24)=1, so the answer is 55.

In the fourth test case:

  • gcd⁡(2,2)=2\gcd(2,2)=2, gcd⁡(2,4)=2\gcd(2,4)=2, gcd⁡(2,6)=2\gcd(2,6)=2, gcd⁡(2,10)=2\gcd(2,10)=2, so 22 cannot be the answer.
  • gcd⁡(3,2)=1\gcd(3,2)=1, so the answer is 33.

在第一个测试用例中,gcd⁡(2,1)=1\gcd(2,1)=1,这是满足条件的最小数。

在第二个测试用例中:

  • gcd⁡(2,6)=2\gcd(2,6)=2,gcd⁡(2,12)=2\gcd(2,12)=2,因此 22 不能作为答案。
  • gcd⁡(3,6)=3\gcd(3,6)=3,gcd⁡(3,12)=3\gcd(3,12)=3,因此 33 不能作为答案。
  • gcd⁡(4,6)=2\gcd(4,6)=2,gcd⁡(4,12)=4\gcd(4,12)=4,因此 44 不能作为答案。
  • gcd⁡(5,6)=1\gcd(5,6)=1,因此答案为 55。

在第三个测试用例中:

  • gcd⁡(2,24)=2\gcd(2,24)=2,gcd⁡(2,120)=2\gcd(2,120)=2,gcd⁡(2,210)=2\gcd(2,210)=2,因此 22 不能作为答案。
  • gcd⁡(3,24)=3\gcd(3,24)=3,gcd⁡(3,120)=3\gcd(3,120)=3,gcd⁡(3,210)=3\gcd(3,210)=3,因此 33 不能作为答案。
  • gcd⁡(4,24)=4\gcd(4,24)=4,gcd⁡(4,120)=4\gcd(4,120)=4,gcd⁡(4,210)=2\gcd(4,210)=2,因此 44 不能作为答案。
  • gcd⁡(5,24)=1\gcd(5,24)=1,因此答案为 55。

在第四个测试用例中:

  • gcd⁡(2,2)=2\gcd(2,2)=2,gcd⁡(2,4)=2\gcd(2,4)=2,gcd⁡(2,6)=2\gcd(2,6)=2,gcd⁡(2,10)=2\gcd(2,10)=2,因此 22 不能作为答案。
  • gcd⁡(3,2)=1\gcd(3,2)=1,因此答案为 33。

输入解题思路,AI测评打分。不知道怎么写?

首页