-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoprime.cpp
More file actions
33 lines (31 loc) · 784 Bytes
/
Copy pathCoprime.cpp
File metadata and controls
33 lines (31 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Codeforces Problem: 1742D - Coprime
// Link: https://codeforces.com/problemset/problem/1742/D
// Status: Accepted Language: C++
#include<iostream>
#include<algorithm>
using namespace std;
int main () {
int t;
cin>>t;
while (t--) {
int arr[1001] ={0};
int n, elm;
cin>>n;
for (int i = 1; i <= n; i++) {
cin>>elm;
arr[elm] = i;
}
int ans = -1;
for (int i = 1; i <= 1000; i++) {
for (int j = i; j <= 1000; j++) {
if (arr[i] > 0 && arr[j] > 0) {
if (__gcd(i, j) == 1) {
ans = max (ans, arr[i] + arr[j]);
}
}
}
}
cout<<ans<<"\n";
}
return 0;
}