倘若存在 1,那么答案是 \(n-cnt_1\)。

否则,设最短的公约数为 1 的区间长度为 \(minlen\),答案是 \(minlen-1+n-1\)。

#include <iostream>
#include <cstdio>
using namespace std;
int n, ans, gcd[2005][2005], cnt;
int getGcd(int x, int y){
return !y?x:getGcd(y, x%y);
}
int getAns(){
if(cnt) return n-cnt;
for(int l=2; l<=n; l++)
for(int i=1; i<=n-l+1; i++){
int j=i+l-1;
gcd[i][j] = getGcd(gcd[i][j-1], gcd[j][j]);
if(gcd[i][j]==1) return n+l-2;
}
return -1;
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
scanf("%d", &gcd[i][i]);
if(gcd[i][i]==1) cnt++;
}
ans = getAns();
cout<<ans<<endl;
return 0;
}

cf891a Pride的更多相关文章

  1. 《傲慢与偏见》(Pride and Prejudice)

    <傲慢与偏见>(Pride and Prejudice)改编自英国作家简·奥斯汀的同名小说,1940年上映.讲述了19世纪初期英国的一个普通的中产家庭中五姐妹的爱情与择偶故事.片中因为男主 ...

  2. Codeforces 892 C.Pride

    C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  3. Codeforces Round #446 (Div. 2) C. Pride【】

    C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  4. Seven Deadly Sins: Gluttony, Greed, Sloth, Wrath, Pride, Lust, and Envy.

    Seven Deadly Sins: Gluttony, Greed, Sloth, Wrath, Pride, Lust, and Envy.七宗罪:暴食.贪婪.懒惰.暴怒.傲慢.色欲.妒忌.

  5. codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony

    A  链接:http://codeforces.com/problemset/problem/892/A 签到 #include <iostream> #include <algor ...

  6. A. Pride

    You have an array a with length n, you can perform operations. Each operation is like this: choose t ...

  7. A. Pride (emmmm练习特判的好题)

    题目连接 : http://codeforces.com/problemset/problem/891/A You have an array a with length n, you can per ...

  8. 【Codeforces Round #446 (Div. 2) C】Pride

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 想一下,感觉最后的结果肯定是从某一段开始,这一段的gcd为1,然后向左和向右扩散的. 则枚举那一段在哪个地方. 我们设这一段中所有的 ...

  9. Lesson 22 A glass envolops

    Text My daughter, Jane, never dreamed of receiving a letter from a girl of her own age in Holland. L ...

随机推荐

  1. Haproxy常见用法

    简介 HAProxy 提供高可用性.负载均衡以及基于 TCP 和 HTTP 应用的代理,支持虚拟主机, 它是免费.快速并且可靠的一种解决方案. HAProxy 特别适用于那些负载特大的 web 站点, ...

  2. 移动端meta的使用

    伴随着web app的不断火热,移动端可以说是未来的大趋势了,下面是常用的一下meta <!-- 声明文档使用的字符编码 --> <meta charset='utf-8'> ...

  3. HTML 5的革新——语义化标签(一)HTML 5的革新——语义化标签(二)

    HTML 5的革新之一:语义化标签一节元素标签. 在HTML 5出来之前,我们用div来表示页面章节,但是这些div都没有实际意义.(即使我们用css样式的id和class形容这块内容的意义).这些标 ...

  4. uvm_factory——我们的工厂(二)

    上节我们说到uvm_object_registry #(T),uvm_object_reistry 又继承自uvm_object_wrapper,所以首先,让我们先看看它爹是啥样子的: //----- ...

  5. 指定ip地址登陆服务器

    [root@localhost ~]# cat /etc/hosts.allow ## hosts.allow   This file contains access rules which are ...

  6. Objective-C Runtime Reference

    This document describes the OS X Objective-C 2.0 runtime library support functions and data structur ...

  7. JS 字符串 时间 数字函数操作 事件

    字符串  操作 var s="abcdefg" s.tolowerCase()   转小写 s.toupperCase()   转大写 s.substring(2,5)   索引下 ...

  8. strongSwan大坑一直重启(ubuntu)

    报错 Starting strongSwan 5.3.2 IPsec [starter]... charon (20533) started after 40 ms charon stopped af ...

  9. windows定时任务小注

    static class Program { /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static vo ...

  10. 51nod 1276 1276 岛屿的数量 (很好玩的题目

    题意: 有N个岛连在一起形成了一个大的岛屿,如果海平面上升超过某些岛的高度时,则这个岛会被淹没.原本的大岛屿则会分为多个小岛屿,如果海平面一直上升,则所有岛都会被淹没在水下. 给出N个岛的高度.然后有 ...