Codeforces Round #446 (Div. 2) C. Pride
#include<bits/stdc++.h>
using namespace std;
#define maxn 2000+100
int a[maxn];
int b[maxn];
int gcd(int a,int b){
int temp;
if(a<b){
temp=a;
a=b;
b=temp;
}
while(b!=0){
temp=a%b;
a=b;
b=temp;
}
return a;
}
int main(){
int n;
cin>>n;
int i=0;
for(int j=1;j<=n;j++){
scanf("%d",&a[j]);
if(a[j]==1) i++;
}
if(i){
cout<<n-i<<endl;
return 0;
}
int ans=20001;
for(int j=1;j<n;j++){
int t=a[j];
for(int k=j+1;k<=n;k++){
t=gcd(t,a[k]);
if(t==1){
ans=min(ans,k-j);
}
}
}
if(ans==20001) cout<<"-1"<<endl;
else cout<<ans+n-1<<endl;
return 0;
}
相關文章
- Codeforces Round #242 (Div. 2) C. Magic FormulasORM
- Codeforces Round #215 (Div. 2) C. Sereja and AlgorithmGo
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 題解】GAM
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Arraydev
- Codeforces C. Colored Rooks 構造 (Codeforces Round #518 (Div. 2) )
- Codeforces Round #688 (Div. 2) C. Triangles(思維,數學)
- C. Lose it!(思維)Codeforces Round #565 (Div. 3)
- Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate 水題
- Codeforces Round #228 (Div. 1) C. Fox and Card GameGAM
- Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二進位制]
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #448 (Div. 2) A
- Codeforces Round #217 (Div. 2)
- Codeforces Round #256 (Div. 2)
- Codeforces Round #259 (Div. 2)
- Codeforces Round #257 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #171 (Div. 2)
- Codeforces Round #173 (Div. 2)
- Codeforces Round 951 (Div. 2)
- Codeforces Round 955 (Div. 2)
- Codeforces Round 953 (Div. 2)
- Codeforces Round 975 (Div. 2)
- Codeforces Round 976 (Div. 2)
- Codeforces Round 972 (Div. 2)
- Codeforces Round 979 (Div. 2)
- Codeforces Round 982 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round 940 (Div. 2)
- Codeforces Round 973 (Div. 2)