重新发一个
2023-08-15 09:37:31
发布于:广东
22阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0)return a;
return gcd(b, a % b);
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[1010] = {0};
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a[x] = i;
}
int cnt = -1;
for (int i = 1; i <= 1000; i++) {
for (int j = i; j <= 1000; j++) {
if (a[i] != 0 && a[j] != 0 && a[i] + a[j] > cnt && gcd(i, j) == 1) {
cnt = a[i] + a[j];
}
}
}
cout << cnt << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个