cf891a Pride
倘若存在 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的更多相关文章
- 《傲慢与偏见》(Pride and Prejudice)
<傲慢与偏见>(Pride and Prejudice)改编自英国作家简·奥斯汀的同名小说,1940年上映.讲述了19世纪初期英国的一个普通的中产家庭中五姐妹的爱情与择偶故事.片中因为男主 ...
- Codeforces 892 C.Pride
C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- 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 ...
- Seven Deadly Sins: Gluttony, Greed, Sloth, Wrath, Pride, Lust, and Envy.
Seven Deadly Sins: Gluttony, Greed, Sloth, Wrath, Pride, Lust, and Envy.七宗罪:暴食.贪婪.懒惰.暴怒.傲慢.色欲.妒忌.
- codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony
A 链接:http://codeforces.com/problemset/problem/892/A 签到 #include <iostream> #include <algor ...
- A. Pride
You have an array a with length n, you can perform operations. Each operation is like this: choose t ...
- A. Pride (emmmm练习特判的好题)
题目连接 : http://codeforces.com/problemset/problem/891/A You have an array a with length n, you can per ...
- 【Codeforces Round #446 (Div. 2) C】Pride
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 想一下,感觉最后的结果肯定是从某一段开始,这一段的gcd为1,然后向左和向右扩散的. 则枚举那一段在哪个地方. 我们设这一段中所有的 ...
- 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 ...
随机推荐
- C51存储的优化
我们知道51单片机只有128BYTE的RAM, 有的增强型有XRAM,此时编程时就要注意,否则就有可能超出空间 1 对于各模块的全局变量.静态变量.全局枚举型常量,静态枚举型常量.个别操作存储(如外部 ...
- hdu4553约会安排(线段树区间合并)
链接 poj3667的加强版 当时的题解 这里只不过对于女神需要另开算,DS的占用的时间不加在女神身上,女神的时间都要加,清空的时候也都要算. #include <iostream> #i ...
- Less的学习和使用
官网 http://less.bootcss.com/usage/ 在线编译器 http://tool.oschina.net/less
- Java编程基础-异常
一.异常 1.什么是异常 在java中,程序在运行时出现的不正常情况称为异常,以异常类的形式对这些非正常情况进行封装,通过异常处理机制对程序运行时发生的各种问题进行处理.其实就是java对不正常情况进 ...
- 慢慢积累遇到的linux指令
sudo 用来以其他身份来执行命令,预设身份为root sudo apt install git 下载git sudo root 进入root身份(只有这个身份ubuntu和window系统之间才能共 ...
- IOS与android
Android和iOS那个好?应该先往哪个上面投入资源?多次被人问到此类问题,笔者刚好自己的项目也需要考虑iOS版本.就索性进行了一番调研,于是有了本文(本次不讨论越狱的iOS) 首先从情感上,你喜欢 ...
- MySQL常用命令和语句
1.常用SQL语句 1)常用函数/*type可取值为:MICROSECONDSECONDMINUTEHOURDAYWEEKMONTHQUARTERYEARSECOND_MICROSECONDMINUT ...
- Spring IOC的Bean对象
---恢复内容开始--- 在Spring IOC模块中Bean是非常重要的.在这里我想给大家讲讲关于Bean对象实例化的三种注入方式: 首先,我先讲一下关于Bean对象属性值的两种注入方式:set注入 ...
- MIPS—冒泡排序
SORT 使用冒泡排序对整数数组进行排序,这种排序虽然不是最快的,但却是最简单的. C语言代码 #include<stdio.h> #include<iostream> usi ...
- 【iview input 回车刷页面bug】input 就一个的时候 有form的时候 回车会刷页面,如果就一个input,可以不要form,或者form里面两个input 将一个input v-show false 就可以了
[iview input 回车刷页面bug]input 就一个的时候 有form的时候 回车会刷页面,如果就一个input,可以不要form,或者form里面两个input 将一个input v-sh ...