798 C. Mike and gcd problem

来源:互联网 发布:手机淘宝如何找同款 编辑:程序博客网 时间:2024/06/05 02:45
#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;}

0 0