Advertisement
fooker

P1742D

Nov 26th, 2022
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. // https://codeforces.com/contest/1742/problem/D
  2. // P 1742 D
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6. #define ll long long
  7. #define FOR(i,a,b) for (ll i=a; i<=b; i++)
  8. #define ROF(i,a,b) for (ll i=a; i>=b; i--)
  9. const ll nmax=1e5+7;
  10. const ll N=1e9+7;
  11. ll gcd_ll(ll a,ll b){
  12.     return (b==0)?(a):(gcd_ll(b,a%b));
  13. }
  14. void solve()
  15. {
  16.     ll n;
  17.     cin>>n;
  18.     ll a[n+2];
  19.     FOR(i,1,n) cin>>a[i];
  20.     ll e=0;
  21.     ROF(i,n,1){
  22.         ll k=i;
  23.         ROF(j,n,i){
  24.             if (gcd_ll(a[k],a[j])==1){
  25.                 ll e=1;
  26.                 cout<<k+j<<"\n";
  27.                 return;
  28.             }
  29.         }
  30.     }
  31.     cout<<-1<<"\n";
  32. }
  33. int main()
  34. {
  35.     int t;
  36.     for (cin>>t; t--; ){
  37.         solve();
  38.     }
  39.  
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement