题干:

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 + 1 and 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 Abeautiful 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.

题目大意:

给定一个n个元素的数组,求最少几次操作可以使 gcd( a1, a2,… ,an )>1 。

定义一次操作是:将删掉,并且加入这两个数。

解题报告:

首先可以证明:如果你开始操作了,那最终一定要凑出2的倍数。如果公因子d是非2的数,那必须是初始序列。

证明如下:运用反证法,对于任意的a和b,操作之后变成a+b和a-b,假设这个公因子d不是2,最终推出矛盾,也就是证明出g必须为2.

首先需要保证d|(a+b) 且 d|(a-b)。(设为式①和式②)

设公因子是d,则a=k1*d+c1 , b=k2*d+c2(且0<c1,c2<d)。带入式①和式②,得d|(c1+c2),且d|(c1-c2).(设为式③和式④)

联立,得c1=c2,所以d|(2*c1),所以d肯定能被2整除。

证毕。

所以我们要通过操作把所有的数字都变成偶数。然后就贪心搞一搞就好了,记录一下有多少个连续的奇数。

因为你会发现

对于两个偶数来说,不需要操作,

对于两个奇数,通过一次操作即可。

对于一奇一偶,通过两次操作即可。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int n,a[MAX],g,cnt,ans;
int main()
{cin>>n;for(int i = 1; i<=n; i++) cin>>a[i],g=__gcd(a[i],g);puts("YES");if(g==1) {for(int i = 1; i<=n; i++) {if(a[i]%2==1) cnt++;else {ans += cnt/2+(cnt%2==1?2:0);cnt=0;} }ans += cnt/2+(cnt%2==1?2:0);}printf("%d\n",ans);return 0 ;
}

【Codeforces - 798C】 Mike and gcd problem(思维,贪心)相关推荐

  1. Codeforces 798C:Mike and gcd problem

    Codeforces 798C:Mike and gcd problem 题目链接:http://codeforces.com/contest/798/problem/C 题目大意:给出一个大小为$n ...

  2. G - Mike and gcd problem

    G - Mike and gcd problem Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the seq ...

  3. codeforces798C - Mike and gcd problem (数论+思维)

    原题链接:http://codeforces.com/contest/798/problem/C 题意:有一个数列A,gcd(a1,a2,a3...,an)>1 时称这个数列是"漂亮& ...

  4. Mike and gcd problem(思维)

    Mike has a sequence A = [a1, a2, -, an] of length n. He considers the sequence B = [b1, b2, -, bn] b ...

  5. 牛客多校4 - Harder Gcd Problem(构造+贪心)

    题目链接:点击查看 题目大意:给出一个 n ,表示 1 ~ n 的 n 个数字,现在要求选出尽可能多的两两匹配,使得每组匹配的 gcd 都大于 1,输出最多能有多少组匹配,以及方案 题目分析: 这样的 ...

  6. Codeforces Round #459 (Div. 2) C 思维,贪心 D 记忆化dp

    Codeforces Round #459 (Div. 2) C. The Monster 题意:定义正确的括号串,是能够全部匹配的左右括号串. 给出一个字符串,有 (.). ? 三种字符, ? 可以 ...

  7. CodeForces - 798D Mike and distribution(构造+思维/玄学随机数)

    题目链接:点击查看 题目大意:给出两个长度为n的数列,现在要求选出n/2+1个位置,使得两个序列中这些位置的和分别大于各自序列之和的一半 题目分析:题意换句话说,是需要让我们从数组中选出一半,要大于另 ...

  8. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 离散化】

    任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...

  9. CodeForces - 798B Mike and strings

    B. Mike and strings time limit per test2 seconds memory limit per test256 megabytes inputstandard in ...

最新文章

  1. 大数据分析与可视化报告会成功召开(附PPT下载)
  2. QT的QGeoRoutingManager类的使用
  3. 面试提问vue中v-if与v-show的区别以及使用场景
  4. python os.access_os.access(path, mode)
  5. GitHub入门详解
  6. c语言编fermat素数检验,记信安实验(一):Fermat 素性检验算法
  7. EJB3.0 Timer
  8. tcp程序——回声客户端
  9. 【第三方互联】12、支付宝(Alipay)授权第三方登录
  10. 男孩只知道疯跑,就像印第安人围着野牛一样
  11. springBoot使用RestTemplate报错:No instance available for xxx.xxx.xxx.xxx
  12. UE打包时候生成多个PAK
  13. Private VLAN 与Switchport Protected
  14. html中字体设置为行书,行书的字体结构,漂亮的行书是如何写出来的(上)
  15. 人脸识别——FaceBook的DeepFace、Google的FaceNet、DeepID
  16. Oracle 不能删除存储过程的处理
  17. 一行代码实现呼出热键
  18. 零基础怎样学IT难吗?新手如何快速入门?
  19. java实现StringBuffer小案例
  20. 最新第四方支付平台程序源码_云计费系统源码

热门文章

  1. android在主程序中调用图片,009android初级篇之APP中使用系统相机相册等集成应用...
  2. java内存溢出让tomcat停止_java - 使用JVM Open J9一段时间后,应用程序(tomcat)停止响应 - 堆栈内存溢出...
  3. l启动进程 linux,《日子》. linux 查看进程启动路径
  4. oracle负数怎么比较大小,输出负数【oracle学习吧】_百度贴吧
  5. 陈伯雄lisp_基于AutoLisp的AutoCAD二次开发自动生成系统图
  6. HEC-RAS如何修改SA/2D Connection的名称
  7. [vc]如何对radio按钮分组
  8. wince中的背光灯控制
  9. WINCE 加入驱动DLL步骤
  10. java修改pdf内容流_java – 在PDFBox中,如何更改PDRectangle对象的原点(0,0)?