Advertisement
Saleh127

CF 891A

Oct 2nd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. ll a[200000],c,d=0,e,f,i,j,k,l=100000000000;
  11. cin>>c;
  12. for(i=0;i<c;i++)
  13. {
  14. cin>>a[i];
  15. if(a[i]==1) d++;
  16. }
  17. if(d)
  18. {
  19. cout<<c-d<<endl;
  20. return 0;
  21. }
  22. for(i=0;i<c;i++)
  23. {
  24. f=a[i];
  25. for(j=i+1;j<c;j++)
  26. {
  27. f=__gcd(f,a[j]);
  28. if(f==1)
  29. {
  30. l=min(l,(j-i));
  31. }
  32. }
  33.  
  34. }
  35. if(l==100000000000) cout<<-1<<endl;
  36. else cout<<l+(c-1)<<endl;
  37. return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement