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.

我不想说,本来可以一次a掉的  硬是搞了好几次,不需要加数的时候0也要输出,

只要判断相邻是否互质,否的时候在中间插入1,因为1和任何数都互质,

英语是硬伤

 #include<iostream>
#include<queue>
#include<cstdio>
#include<cstdio>
#include<cstring>
using namespace std;
int fun(int m,int n)
{
if(m<n)
{
n=m+n;
m=n-m;
n=n-m;
}
int t;
while(m%n!=)
{
t=n;
n=m%n;
m=t;
}
return n;
}
int main()
{
queue<int>Q;
int a[],b[];
int n,t;
int i,j;
while(cin>>n)
{
t=;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(i=;i<=n;i++)
{
cin>>a[i];
}
b[t]=a[];
for(j=;j<=n;j++)
{
if(fun(b[t],a[j])==)
{
b[++t]=a[j];
}
else
{
b[++t]=;
b[++t]=a[j];
}
}
cout<<t-n<<endl;
cout<<b[];
for(i=;i<=t;i++)
cout<<" "<<b[i];
cout<<endl; }
return ;
}

Sample Input

Input
3
2 7 28
Output
1
2 7 9 28

CodeForces 660A的更多相关文章

  1. Codeforces 660A. Co-prime Array 最大公约数

    A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. codeforces 660A A. Co-prime Array(水题)

    题目链接: A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input stand ...

  3. CodeForces 660A Co-prime Array

    水题.放个1就可以了.暴力的找数字也是很快的. #include<cstdio> #include<cstring> #include<cmath> #includ ...

  4. Co-prime Array&&Seating On Bus(两道水题)

     Co-prime Array Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. [转]ORACLE EXECUTE IMMEDIATE 小结

    转自:http://www.cnblogs.com/huanghai223/archive/2011/06/29/2093660.html   EXECUTE IMMEDIATE 代替了以前Oracl ...

  2. 五分钟学习React(六):元素(Element)和组件(Component)

    俗话说"万丈高楼平地起",从这一期开始,我们将使用基于Webpack+Babel的React学习React框架中的一些基础概念.在学习React的过程中经常会把Element.Cl ...

  3. GraphicsMagick在centos环境的安装

    一.需要安装包libpng-1.6.2rc02.tar.gz,libjpeg-6b.tar.gz,GraphicsMagick-1.3.18.tar.gz,GraphicsMagick-1.3.18最 ...

  4. dubbo之本地调用

    本地调用 本地调用使用了 injvm 协议,是一个伪协议,它不开启端口,不发起远程调用,只在 JVM 内直接关联,但执行 Dubbo 的 Filter 链. 配置 定义 injvm 协议 <du ...

  5. AMQP及RabbitMQ

    AMQPAMQP协议是一个高级抽象层消息通信协议,RabbitMQ是AMQP协议的实现.它主要包括以下组件: 1.Server(broker): 接受客户端连接,实现AMQP消息队列和路由功能的进程. ...

  6. 通过yum仓库安装mysql

    1,下载安装包wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm2,安装mysql源yum -y ins ...

  7. jquery获取当前时间并且格式化

    Date.prototype.Format = function (fmt) {      var o = {          "M+": this.getMonth() + 1 ...

  8. eas之单据转换规则

    /**  * BOTP单据转换  * @param botpNum 转换规则编号  * @param BillInfo 原单据  */ public static void BOTP(String b ...

  9. LA 4327

    Panagola, The Lord of city F likes to parade very much. He always inspects his city in his car and e ...

  10. 进程(day09)

    进程的管理 一.进程的基础 进程和程序的区别 每个进程有自己的pid.PCB 操作系统上运行的所有进程构成一颗树. 如何查看这颗树? pstree() 树根进程是init pid是 进程间的亲缘关系两 ...