Description

Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. .

Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1and put numbers ai - ai + 1, ai+ ai + 1 in their place instead, in this order. He wants perform as few operations as possible. Find the minimal number of operations to make sequence A beautiful if it's possible, or tell him that it is impossible to do so.

 is the biggest non-negative number d such that d divides bi for every i (1 ≤ i ≤ n).

Input

The first line contains a single integer n (2 ≤ n ≤ 100 000) — length of sequence A.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of sequence A.

Output

Output on the first line "YES" (without quotes) if it is possible to make sequence A beautiful by performing operations described above, and "NO" (without quotes) otherwise.

If the answer was "YES", output the minimal number of moves needed to make sequence A beautiful.

Examples
input
2
1 1
output
YES
1
input
3
6 2 4
output
YES
0
input
2
1 3
output
YES
1
Note

In the first example you can simply make one move to obtain sequence [0, 2] with .

In the second example the gcd of the sequence is already greater than 1.

题意:要使得,我们可以这样修改 ai - ai + 1, ai+ ai + 1,问最少修改次数

解法:按照上面操作把所有的数字变成偶数就行了

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
int x[maxn];
int n;
int num;
int sum;
int main()
{
cin>>n;
cin>>x[];
num=x[];
for(int i=; i<=n; i++)
{
cin>>x[i];
num=__gcd(x[i],num);
}
// cout<<num<<endl;
if(num>)
{
cout<<"YES\n0\n";
return ;
}
for(int i=; i<n; i++)
{
while(x[i]%)
{
int pos=x[i];
x[i]-=x[i+];
x[i+]+=pos;
sum++;
}
}
// cout<<x[n]<<endl;
while(x[n]%)
{
int pos=x[n-];
x[n-]-=x[n];
x[n]+=pos;
sum++;
}
cout<<"YES\n";
cout<<sum<<endl;
return ;
}

Codeforces Round #410 (Div. 2) C的更多相关文章

  1. Codeforces Round #410 (Div. 2)

    Codeforces Round #410 (Div. 2) A B略..A没判本来就是回文WA了一次gg C.Mike and gcd problem 题意:一个序列每次可以把\(a_i, a_{i ...

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

    题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...

  3. Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)

    A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  4. Codeforces Round #410 (Div. 2)A B C D 暴力 暴力 思路 姿势/随机

    A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  5. Codeforces Round #410 (Div. 2) A. Mike and palindrome

    A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. Codeforces Round #410 (Div. 2) A

    Description Mike has a string s consisting of only lowercase English letters. He wants to change exa ...

  7. Codeforces Round #410 (Div. 2) A. Mike and palindrome【判断能否只修改一个字符使其变成回文串】

    A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  8. Codeforces Round #410 (Div. 2)D题

    D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. Codeforces Round #410 (Div. 2)C题

    C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  10. Codeforces Round #410 (Div. 2) B

    B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. WPF新手之如何将数据绑定到TreeView

    看过许多例子,全是绑定到类的,没人说如何绑定到某个对象,偏偏我这个绝对的新手就是要绑定到一个对象,只能自己摸索了: 首先要将数据绑定到容器,有以下几个默认条件:①元数据必须包装在List或者Obser ...

  2. LeetCode(67)题解: Add Binary

    https://leetcode.com/problems/add-binary/ 题目: Given two binary strings, return their sum (also a bin ...

  3. Python2.7安装教程

    作者:zhanhailiang 日期:2014-11-16 [root@~/software]# yum install bzip* [root@~/software]# wget http://ww ...

  4. iOS 各种编译错误汇总

    1.error: macro names must be identifiers YourProject_prefix.pch 原因: 因为你弄脏了预处理器宏,在它处于<Multiple Val ...

  5. apache benchmark

    1 ab是什么 是一个web高并发测试工具,可以发送get.put.post请求. 2 ab -n和-c共存 -c是concurrency的缩写,即同一时间发送多个请求. -n是指本次总共发送多少个请 ...

  6. Hashed Indexes Geospatial Index

    Indexes — MongoDB Manual https://docs.mongodb.com/manual/indexes/ 地理索引 哈希索引

  7. Mongo.setReadPref(mode, tagSet) primaries and secondaries are treated equivalently. 读优先级策略

    https://docs.mongodb.com/manual/reference/method/Mongo.setReadPref/#Mongo.setReadPref Mongo.setReadP ...

  8. ping 和 远程桌面 与防火墙的关系

    现象: 初始化服务器时,人们为了方便,常常关闭防火墙,这样做很危险.我们经常遇到问题是,防火墙一旦打开,ping和远程桌面就会有问题. 有时ping不通,但能远程:但有时ping通,又远程不了:有时都 ...

  9. javascript XMLHttpRequest 对象的open() 方法参数说明

    下文是从w3c上摘录下来的,其中参数 method 说明的很简短,不是很理解,所以又找了些资料作为补充.文中带括号部分. XMLHttpRequest.open() 初始化 HTTP 请求参数 语法o ...

  10. 一步一步学Silverlight 2系列(8):使用样式封装控件观感

    述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...