如果一开始就满足题意,不用变换。

否则,如果对一对ai,ai+1用此变换,设新的gcd为d,则有(ai - ai+1)mod d = 0,(ai + ai+1)mod d = 0

变化一下就是2 ai mod d = 0

2 ai+1 mod d = 0

也就是说,用两次变换之后,gcd至少扩大2倍,于是,最优方案就是我们将所有的奇数都变成偶数。

只需要找出所有奇数段,答案就是sigma([奇数段的长度/2]+(奇数段的长度 mod 2 ==1 ?))。

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
ll a[100010];
int main(){
// freopen("c.in","r",stdin);
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%I64d",&a[i]);
}
int GCD=(int)a[1];
for(int i=2;i<=n;++i){
GCD=__gcd(GCD,(int)a[i]);
}
if(GCD!=1){
puts("YES\n0");
return 0;
}
int cnt=0,sta;
for(int i=1;i<=n;++i){
if(a[i]%2ll==1 && (i==1 || a[i-1]%2ll==0)){
sta=i;
}
if(a[i]%2ll==1 && (i==n || a[i+1]%2ll==0)){
cnt+=(i-sta+1)/2+((i-sta+1)%2==1 ? 2 : 0);
}
}
printf("YES\n%d\n",cnt);
return 0;
}

【推导】Codeforces Round #410 (Div. 2) C. Mike and gcd problem的更多相关文章

  1. 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 ...

  2. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合

    E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...

  3. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】

    任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...

  4. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化+逆元

    E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #410 (Div. 2) B. Mike and strings

    B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)

    传送门 Description Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In ...

  9. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem

    题目链接:传送门 题目大意:给你n个区间,求任意k个区间交所包含点的数目之和. 题目思路:将n个区间都离散化掉,然后对于一个覆盖的区间,如果覆盖数cnt>=k,则数目应该加上 区间长度*(cnt ...

随机推荐

  1. ImageView设置边框 以及内部图片居中显示 在AndroidStudio中添加shape.xml文件

    效果如图 边框设置:shape文件 <shape xmlns:android="http://schemas.android.com/apk/res/android"> ...

  2. VMware12序列号

    VMware tools怎么删除 rpm -e open-vm-tools-desktop vm12序列号 5A02H-AU243-TZJ49-GTC7K-3C61NVF5XA-FNDDJ-085GZ ...

  3. System and method to prioritize large memory page allocation in virtualized systems

    The prioritization of large memory page mapping is a function of the access bits in the L1 page tabl ...

  4. (十五)linux下gdb调试

    一.gdb常用命令: 命令 描述 backtrace(或bt) 查看各级函数调用及参数 finish 连续运行到当前函数返回为止,然后停下来等待命令 frame(或f) 帧编号 选择栈帧 info(或 ...

  5. 单从软件层面来说,Maya 和 Blender 差别在哪?

    单从软件层面来说,Maya 和 Blender 差别在哪? https://www.zhihu.com/question/21975571

  6. 【java报错】Unknown character set index for field '224' received from server.

    在捣腾免费数据库时,使用的一个数据库提供商的服务器使用utf8mb4编码,而我的jar包还是八百年前的.然后...然后就报错了... (1) MYSQL 5.5 之前, UTF8 编码只支持1-3个字 ...

  7. C++中delete和delete[]的区别(转)

    原文链接:http://www.cnblogs.com/charley_yang/archive/2010/12/08/1899982.html 一直对C++中的delete和delete[]的区别不 ...

  8. python插入oracle数据

    # coding=utf- ''''' Created on -- @author: ''' import json; import urllib2 import sys import cx_Orac ...

  9. 关于springMVC转换json出现的异常

    jackson-core-asl-1.9.0.jar,jackson-mapper-asl-1.9.0.jar两个包 并且在controller中有如下代码 @RequestMapping(value ...

  10. Restful Framework 初识

    目录 一.什么是RESTful 二.什么是API 三.RESTful API规范 四.基于Django实现API 五.基于Django Rest Framework框架实现 一. 什么是RESTful ...