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. TestNG – Run multiple test classes (suite test)

    In this tutorial, we will show you how to run multiple TestNG test cases (classes) together, aka sui ...

  2. 浅谈JavaScript的事件(事件流)

     事件流描述的是从页面中接收事件的顺序.IE的事件流失事件冒泡,而Netspace的事件流失事件捕获. 事件冒泡 IE的事件流叫事件冒泡,即事件开始时,由具体的元素(文档中嵌套层次最深的节点)接收,然 ...

  3. scala快速学习笔记(三):Collections,包

    VI.Collections 1.Array 一些常用方法:println,  map( _ * 2), filter(_ % 2 == 0),  sum,   reserve Array是不可变的, ...

  4. 利用BADI WORKORDER_INFOSYSTEM在COOIS中加入自己定义列办事处

    需求描写叙述:依据LC业务部门提出的需求.须要在COOIS中加入办事处一列. 1.在IOHEADER_TAB的CI_IOHEADER中加入字段办事处.如以下图所看到的:   watermark/2/t ...

  5. 简单的shell脚本编写

    http://www.cnblogs.com/wuyuegb2312/p/3399566.html

  6. querying rpm database

    Call dbMatch on a transaction set to create a match iterator. As with the C API, a match iterator al ...

  7. MIPS 指令集将在近期开源,RISC-V 阵营慌吗?

    消息称,MIPS 指令集即将开源. eetimes 17 日报导,Wave Computing 公司表示,在明年第一季度发布最新 MIPS 指令集体系和 MIPS 最新内核 R6 的时候将开源 MIP ...

  8. jQuery整理笔记九----功能性表格开发

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/hai_cheng001/article/details/27536965 演示样例中用到的一些图片. ...

  9. Ghost wenjian目录

    SOAMANAGER打不开网页,需要配置ghost 文件, C:\Windows\System32\drivers\etc   

  10. jquery和CSS3带倒影的3D万花筒旋转动画特效效果演示

    <!DOCTYPE html> <html> <head> <title></title> <meta charset='utf-8' ...