304168: CF798C. Mike and gcd problem
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Mike and gcd problem
题意翻译
# 问题描述 Mike给定一个$n$个元素的整数序列,$A=[a1,a2,...,an]$,每次操作可以选择一个 $i (1 \le i<n)$,将$a[i],a[i+1]$变成 $a[i]-a[i+1]$和$a[i]+a[i+1]$。现在想要的是$A$序列所有元素的最大公约数大于$1$ 1,请计算最少的操作次数。 # 输入数据 第一行一个整数 $n (2 \le n \le 100000)$ 第二行$n$个整数 $a1,a2,...,an (1 \le ai \le 10^9)$ # 输出 两行 第一行 一个字符串$YES$或$NO$表示能否使公约数大于1 第二行一个整数,表示最少的操作次数,如果无解输出 −1.题目描述
Mike has a sequence $ A=[a_{1},a_{2},...,a_{n}] $ of length $ n $ . He considers the sequence $ B=[b_{1},b_{2},...,b_{n}] $ beautiful if the $ gcd $ of all its elements is bigger than $ 1 $ , i.e. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF798C/11fc4821110b970a70c2486c7b1391945362cd14.png). 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 $ a_{i},a_{i+1} $ and put numbers $ a_{i}-a_{i+1},a_{i}+a_{i+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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF798C/99bfd9bc11b0e82a5c17dd17561cbac80e461b2d.png) is the biggest non-negative number $ d $ such that $ d $ divides $ b_{i} $ for every $ i $ ( $ 1<=i<=n $ ).输入输出格式
输入格式
The first line contains a single integer $ n $ ( $ 2<=n<=100000 $ ) — length of sequence $ A $ . The second line contains $ n $ space-separated integers $ a_{1},a_{2},...,a_{n} $ ( $ 1<=a_{i}<=10^{9} $ ) — elements of sequence $ A $ .
输出格式
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.
输入输出样例
输入样例 #1
2
1 1
输出样例 #1
YES
1
输入样例 #2
3
6 2 4
输出样例 #2
YES
0
输入样例 #3
2
1 3
输出样例 #3
YES
1