【算法系列学习】codeforces C. Mike and gcd problem
2017-04-24 20:12
495 查看
C. Mike and gcd problem
http://www.cnblogs.com/BBBob/p/6746721.html
View Code
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 }
View Code
相关文章推荐
- 【算法系列学习】codeforces D. Mike and distribution 二维贪心
- Mike and gcd problem Codeforces Round #410 (Div. 2)
- Codeforces Round #410 (Div. 2) Mike and gcd problem 思维
- Codeforces Round #410 (Div.2) C.Mike and gcd problem-数学
- Mike and gcd problem CodeForces - 798C
- Codeforces Round #361 (Div. 2)E. Mike and Geometry Problem
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #305 (Div. 2)B. Mike and Fun
- Codeforces Round #253 (Div. 1) B. Andrey and Problem
- Codeforces Round #305 C. Mike and Frog
- Codeforces Round #305 (Div. 1)E. Mike and Friends 后缀数组+RMQ+线段树
- Codeforces Round #305 (Div. 2) C. Mike and Frog +B. Mike and Fun
- Chef and Prime Divisors Problem code: CHAPD (GCD问题)
- Codeforces Round #280 (Div. 2) E. Vanya and Field (数学GCD)
- Codeforces Round #228 (Div. 2), problem: (A) Fox and Number Game
- Codeforces Round #305 (Div. 2)--A. Mike and Fax
- Codeforces Round #253 (Div. 2) D. Andrey and Problem
- codeforces#253 D - Andrey and Problem里的数学知识
- Codeforces Round #253 (Div. 1) B. Andrey and Problem