Codeforces Round #410 (Div. 2), problem: (C) Mike and gcd problem Solution In C/C++

#include <bits/stdc++.h>

using namespace std;
int main(){
int n, num = 0, x, sum = 0;
scanf(“%d”, &n);
int g=0;
for(int i = 0; i < n; ++i){
scanf(“%d”, &x);
g=__gcd(g,x);
if(x&1){
num ++;
}else{
sum = sum + num/2 + (num%2)*2;
num = 0;
}
}

if(num) sum = sum + num/2 + (num%2)*2;
if (g>1)sum=0;
printf(“YES\n%d\n”, sum);
return 0;
}

#include <bits/stdc++.h>

using namespace std;
int main(){
int n, num = 0, x, sum = 0;
scanf(“%d”, &n);
int g=0;
for(int i = 0; i < n; ++i){
scanf(“%d”, &x);
g=__gcd(g,x);
if(x&1){
num ++;
}else{
sum = sum + num/2 + (num%2)*2;
num = 0;
}
}

if(num) sum = sum + num/2 + (num%2)*2;
if (g>1)sum=0;
printf(“YES\n%d\n”, sum);
return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Where the OKC Thunder Rank Among the Top 10 NBA Teams Entering August

As the offseason progresses into August, the NBA landscape continues to undergo dramatic transformations. Major headline-grabbing moves, including LeBron James making his historic transition...

Stop Buying Cheap Alternatives This Portable Blender Bottle Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Famed mountaineer Nirmal Purja, 43, among 10 climbers killed after avalanche in Pakistan

Tragedy in the Karakoram: Nirmal Purja Among 10 Lost in Avalanche In a devastating turn of events for the global mountaineering community, renowned high-altitude climber...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!