您的位置:首页 > 其它

Codeforces Round #410 (Div. 2)C题

2017-04-22 13:55 295 查看
C. Mike and gcd problem

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

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.

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007

using namespace std;

const int N=100000+5,maxn=100000+5,inf=0x3f3f3f3f;

ll n,a
,ans=0;

ll gcd(ll a,ll b)
{
return b? gcd(b,a%b):a;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
ll ans=0,x;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(i==0)x=a[i];
else x=gcd(x,a[i]);
a[i]%=2;
}
if(x>1)
{
cout<<"YES"<<endl<<0<<endl;
return 0;
}
for(int i=0;i<n;i++)
{
if(a[i]==1)
{
if(i+1<n)
{
if(a[i+1]==1)ans++,a[i+1]=0;
else if(a[i+1]==0)ans+=2;
a[i]=0;
}
else ans+=2;
}
}
cout<<"YES"<<endl<<ans<<endl;
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: