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.
View Code
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
相关文章推荐
- Codeforces Round #410 (Div. 2)
- Codeforces Round #410 (Div. 2)
- Codeforces Round #410 (Div. 2) A
- Codeforces Round #410 Div2 D Mike and distribution
- Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)
- Codeforces Round #410 (Div. 2) Mike and gcd problem 思维
- Codeforces Round #410 (Div. 2)
- Mike and gcd problem Codeforces Round #410 (Div. 2)
- Codeforces Round #410 (Div. 2)D题
- Codeforces Round #410 (Div. 2) D. Mike and distribution(贪心)
- Codeforces Round #154 (Div. 2) / 253A Boys and Girls(贪心)
- Codeforces Round #431 (Div. 2)B Tell Your World
- Codeforces Beta Round #61 (Div. 2) B. Petya and Countryside (DP)
- Codeforces Round #285 (Div. 2)A.(手速)
- Codeforces Round #382 (Div. 1) C. Ostap and Tree(树形DP)
- Codeforces Round #360 (Div. 2) E. The Values You Can Make dp ,滚动数组
- Codeforces Round #433 (Div. 2) A.Fraction(暴力)
- Codeforces Round #383 (Div. 1)
- Codeforces Round #433 (Div. 2 D. Jury Meeting 二分
- Codeforces Round #306 (Div. 2) 题解