首页 > 代码库 > 【算法系列学习】codeforces C. Mike and gcd problem
【算法系列学习】codeforces C. Mike and gcd problem
C. Mike and gcd problem
http://www.cnblogs.com/BBBob/p/6746721.html
1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 8 using namespace std; 9 const int maxn=1e5+10; 10 int a[maxn]; 11 12 int gcd(int a,int b) 13 { 14 if(b==0) 15 { 16 return a; 17 } 18 return gcd(b,a%b); 19 } 20 int main() 21 { 22 int n; 23 scanf("%d",&n); 24 for(int i=0;i<n;i++) 25 { 26 scanf("%d",&a[i]); 27 } 28 int g=a[0]; 29 for(int i=1;i<n;i++) 30 { 31 g=gcd(g,a[i]); 32 } 33 if(g!=1) 34 { 35 printf("YES\n"); 36 printf("0"); 37 return 0; 38 } 39 int ans=0; 40 for(int i=0;i<n;i++) 41 { 42 if(a[i]%2==1) 43 { 44 if(a[i+1]%2==1) 45 { 46 ans++; 47 } 48 else 49 { 50 ans+=2; 51 } 52 i++; 53 } 54 } 55 printf("YES\n"); 56 printf("%d\n",ans); 57 return 0; 58 }
【算法系列学习】codeforces C. Mike and gcd problem
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。