Codeforces Round #410 (Div. 2) C
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).
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 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.
2
1 1
YES
1
3
6 2 4
YES
0
2
1 3
YES
1
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的更多相关文章
- Codeforces Round #410 (Div. 2)
Codeforces Round #410 (Div. 2) A B略..A没判本来就是回文WA了一次gg C.Mike and gcd problem 题意:一个序列每次可以把\(a_i, a_{i ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #410 (Div. 2) A
Description Mike has a string s consisting of only lowercase English letters. He wants to change exa ...
- 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 ...
- Codeforces Round #410 (Div. 2)D题
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 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 ...
- Codeforces Round #410 (Div. 2) B
B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- Python 学习资料分享
有同学需要学习 Python,确实,随着人工智能被炒的火热,再加上大数据时代,作为程序员的我们,怎么可能坐得住,必须尝尝鲜,给自己增加一项技能,增加自己的竞争了. 内容定位 这方面的学习资料比较多,本 ...
- Chrome浏览器V43版本号不支持silverlight 5.0的解决的方法
场景: 浏览器:chrome V43 插件:silverlight 5.0 操作系统:xp 问题: 自己开发silverlight站点在IE7和firefox中能正常打开,但在chrome中打开失败. ...
- android自己定义开关控件
近日在android项目要使用开关控件.可是android中自带的开关控件不太惬意,所以就打算通过自己定义View写一个开关控件 ios的开关控件当然就是我要仿照的目标. 先上图: waterma ...
- SQL常见问题及解决备忘
1.mysql中:you cant't specify tartget table for update in from clause 错误 含义:在同一语句中update或delete某张表的时候, ...
- hadoop的一般端口使用
- because joins aren’t as important.
“MongoDB wasn’t designed in a lab. We built MongoDB from our own experiences building large-scale, h ...
- Hibernate的一些使用技巧
1.Hibernate是如今最流行的开源对象关系映射(ORM)持久化框架,SSH框架组合是很多JavaEE工程的首选,java持久化框架(JPA)的设计师是Hibernate的作者,因此对于Hiber ...
- Android Studio解决导入项目非常慢
Android Studio比Eclipse ADT有巨大的优势.Android Studio原生支持使用Gradle来构建项目,使用动态语言Groovy定义项目构建的过程,避免了build.xml文 ...
- elastica安装
https://www.elastic.co/guide/en/elasticsearch/reference/current/zip-targz.html
- GNU Makeflie
简介 Gnu Make主要用于构建和管理程序包.Makefile文件描述了整个工程的编译.连接等规则. 其中包括: 工程中的哪些源文件需要编译以及如何编译: 需要创建那些库文件以及如何创建这些库文件: ...