-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1742D_ Coprime
More file actions
50 lines (38 loc) · 985 Bytes
/
1742D_ Coprime
File metadata and controls
50 lines (38 loc) · 985 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll prime(ll x,ll y){
if(__gcd(x,y)==1)return 1;
return 0;
}
int main()
{
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
ll arr[n+1],a[10000]={0};
map<ll,ll>m;
vector<pair<ll,ll>>v,x;
for(ll i=0;i<n;i++){
cin>>arr[i];
v.push_back({arr[i],i});
}
for(ll i=n-1;i>=0;i--){
if(a[v[i].first]==0)x.push_back({v[i].first,v[i].second});
a[v[i].first]=1;
}
// for(ll i=0;i<x.size();i++)cout<<x[i].first<<" "<<x[i].second<<endl;
ll mp=-1;
for(ll i=0;i<x.size();i++){
for(ll j=i;j<x.size();j++){
if(prime(x[i].first,x[j].first))mp=max(mp,x[i].second+x[j].second);
}
}
if(mp==-1)
cout<<mp<<endl;
else cout<<mp+2<<endl;;
}
return 0;
}