Educational Codeforces Round 11 A. Co-prime Array 水题
A. Co-prime Array
题目连接:
http://www.codeforces.com/contest/660/problem/A
Description
You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
Input
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Output
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it.
If there are multiple answers you can print any one of them.
Sample Input
3
2 7 28
Sample Output
1
2 7 9 28
Hint
题意
给你一个序列,让你插入最小的数,使得任意相邻的两个数都互质
让你输出最后的序列长什么样
题解:
显然插入的数最优就是1嘛,1和任何数都互质
然后我们贪心的去插就好了,能插就插
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
int a[maxn];
int gcd(int a,int b)
{
if(b==0)return a;
return gcd(b,a%b);
}
vector<pair<int,int> >P;
int main()
{
int n;scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<n;i++)
{
if(gcd(a[i],a[i+1])!=1)
P.push_back(make_pair(1,i));
}
cout<<P.size()<<endl;
int j = 0;
for(int i=1;i<=n;i++)
{
cout<<a[i]<<" ";
if(j<P.size()&&P[j].second==i)
{
cout<<P[j].first<<" ";
j++;
}
}
cout<<endl;
}
Educational Codeforces Round 11 A. Co-prime Array 水题的更多相关文章
- Educational Codeforces Round 11 B. Seating On Bus 水题
B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- Educational Codeforces Round 12 A. Buses Between Cities 水题
A. Buses Between Cities 题目连接: http://www.codeforces.com/contest/665/problem/A Description Buses run ...
- Educational Codeforces Round 4 A. The Text Splitting 水题
A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...
- Codeforces Educational Codeforces Round 3 B. The Best Gift 水题
B. The Best Gift 题目连接: http://www.codeforces.com/contest/609/problem/B Description Emily's birthday ...
- Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题
A. USB Flash Drives 题目连接: http://www.codeforces.com/contest/609/problem/A Description Sean is trying ...
- Educational Codeforces Round 13 D. Iterated Linear Function 水题
D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...
- Educational Codeforces Round 13 C. Joty and Chocolate 水题
C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...
- Educational Codeforces Round 13 B. The Same Calendar 水题
B. The Same Calendar 题目连接: http://www.codeforces.com/contest/678/problem/B Description The girl Tayl ...
- Educational Codeforces Round 13 A. Johny Likes Numbers 水题
A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes ...
随机推荐
- 仿360影视网站模板html
链接:http://pan.baidu.com/s/1mhIkV4s 密码:9wgq
- 如何通过掩码计算可用的IP数量
假设掩码是28,28也就是28个1.本身掩码是255.255.255.255那么转换成二进制也就是 11111111,11111111,11111111,11111111 那么28个1也就是: 111 ...
- Cesium 初始化Viewer
<pre name="code" class="javascript"><script> var viewer = new Cesium ...
- Linux实用命令之git-svn
近日发现了有一个工具,git-svn,可以打通git svn之间的鸿沟. 很适合习惯于git,却需要维护svn代码的同学. 安装 sudo apt-get install git-svn 具体使用就不 ...
- 【题解】BZOJ 3600: 没有人的算术——替罪羊树、线段树
题目传送门 题意 具体的自己去上面看吧...反正不是权限题. 简单来说,就是定义了一类新的数,每个数是0或者为 \((x_L, x_R)\) ,同时定义比较大小的方式为:非零数大于零,否则按字典序比较 ...
- PyQt:eg4
import sys from PyQt4 import QtCore from PyQt4 import QtGui class Form(QtGui.QDialog): def __init__( ...
- 报错:/application/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
启动zabbix_server时报错: /application/zabbix/sbin/zabbix_server: error while loading shared libraries: li ...
- Spring中的@Transactional事务注解
事务注解方式 @Transactional 当标于类前时, 标示类中所有方法都进行事物处理 , 例子: @Transactional public class TestServiceBean impl ...
- 如何将qlv格式的腾讯视频转换为mp4格式
一般来说,每个视频网站都会有自己的视频播放格式,如优酷的KUX.爱奇艺的QSV和腾讯的QLV等. 但是大家知道,优酷是有转码功能的,而就目前来说腾讯视频还没有转码功能,下面是将qlv格式的腾讯视频转换 ...
- C#+TaskScheduler(定时任务)实现定时自动下载
C# /TaskScheduler /定时任务 /定时自动下载 3410 实现原理,客户是广电,在广电服务器创建一个FTP目录,然后每天自动从卫星上自动更新节目列表, 然后功能就是要每天定点一个时间自 ...