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 ...
 
随机推荐
- [已读]用Angularjs开发下一代web应用
			
屯了很久了,貌似是国内出现的第一本讲angularjs的书...上上周看完的时候,angular2都要出来了...angular的双向绑定很赞,因为之前公司后台系统我都用tmodjs做,模板语法什么的 ...
 - Linux磁盘根目录满了问题解析
			
linux里的log文件被删除后,空间没有被释放,是因为在Linux系统中,通过rm或者文件管理器删除文件将会从文件系统的目录结构上解除链接(unlink).然而如果文件是被打开的(有一个进程正在使用 ...
 - CF1062D Fun with Integers
			
思路: 找规律. 实现: #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ...
 - git clone  fatal: unable to access 'https://github.com/carlon/demo.git/': Failed to connect to github.com port 443: Timed out
			
$ git config --global http.proxy $ git config --global --unset http.proxy 虽然之前没有设置代理,但是不知道为什么执行以上代码之 ...
 - android sdk更新失败的解决方法
			
[解决方法] 选择Tools-Options,在弹出的设置窗口中,「HTTP Proxy Server」和「HTTP Proxy Port」输入框内填入mirrors.neusoft.edu.cn和8 ...
 - ionic2 tabs 自定义图标
			
ionic2 tabs 自定义图标 一.准备资源 tabs icon 的svg格式的矢量图片 二.生成字体样式文件 打开icoMoon网站去制作字体文件. 三.使用字体文件 解压下载的文件,将其中的f ...
 - 起学习iOS开发专用词汇
			
今天的单词分别是: l Asynchronous 形容词 异步的 n 副词形式: asynchronously 异步地 n 缩写:ASYNC n 反义词:synchronous 形容词同步 ...
 - 【Web应用】JAVA网络上传大文件报500错误
			
问题描述 当通过 JAVA 网站上传大文件,会报 500 错误. 问题分析 因为 Azure 的 Java 网站都是基于 IIS 转发的,所以我们需要关注 IIS 的文件上传限制以及 requestT ...
 - Linux中配置系统参数
			
[root@localhost ~]# vim /etc/security/limits.conf root soft nofile 65535root hard nofile 65535* soft ...
 - 如何在腾讯云上安装Cloud Foundry
			
Cloud Foundry是VMware推出的业界第一个开源PaaS云平台,它支持多种框架.语言.运行时环境.云平台及应用服务,使开发人员能够在几秒钟内进行应用程序的部署和扩展,无需担心任何基础架构的 ...