算法系列学习codeforces C. Mike and gcd problem

Posted shulin~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了算法系列学习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 }
View Code

 

以上是关于算法系列学习codeforces C. Mike and gcd problem的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #410 (Div. 2)C. Mike and gcd problem(数论)

[卿学姐带飞系列]-Codeforces Round #410 (Div. 2)_B - Mike and strings

Codeforces Round #746 (Div. 2) C. Bakry and Partitioning

codeforces #305 D Mike and Fish

Codeforces 845 C. Two TVs 简单贪心算法

CF Round410 C. Mike and gcd problem