您的位置:首页 > 其它

798 C. Mike and gcd problem

2017-04-25 09:49 357 查看
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;

int gcd(int a, int b){
while (a > 0){
int c = b%a;
b = a;
a = c;
}
return b;
}

int main(){
int n;
while (cin >> n){
vector<int> demo(n);
int temp_c = 0;
int amount = 0;
int g = 0;
for (int i = 0; i < n; i++){
cin >> demo[i];
g = gcd(g, demo[i]);
if (demo[i] % 2) temp_c++;
else {
amount += (temp_c / 2) + 2 * (temp_c % 2);
temp_c = 0;
}
}
amount += (temp_c / 2) + 2 * (temp_c % 2);
cout << "YES" << endl;
if (g == 1) cout << amount << endl;
else cout << "0" << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: