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. Java冒泡,快速,插入,选择排序^_^+二分算法查找

    这段时间在学Java,期间学到了一些排序和查找方法.特此写来和大家交流,也方便自己的日后查看与复习. 1.下边是Java的主类: public class Get { public static vo ...

  2. Android Studio and Gradle安装心得

    安装基于Eclipse 的ADT一段时间,感觉确实有很多功能不足,通过网上资料,决定改向AS. AS下载了最新的2.3版本,它不分64位与32位,网上说有单独版是瞎扯蛋.只要启动不同的EXE就行了. ...

  3. Android_传感器光学

    上一篇写了一个小案例方向传感器,与这光学传感器原理大致类似,但其实代码的主要区别得到的类型不一样在这里我一一列举出来: * Sensor.TYPE_ORIENTATION:方向传感器. * Senso ...

  4. 省市区县的sql语句——区县

    DROP TABLE IF EXISTS `area`; CREATE TABLE `area` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `code` va ...

  5. js 事件冒泡、事件捕获、stopPropagation、preventDefault

    转自:http://www.jb51.net/article/42492.htm (1)冒泡型事件:事件按照从最特定的事件目标到最不特定的事件目标(document对象)的顺序触发. IE 5.5: ...

  6. 三维重建5:场景中语义分析/语义SLAM/DCNN-大尺度SLAM

    前言: 在实时/非实时大规模三维场景重建中,引入了语义SLAM这个概念,参考三维重建:SLAM的尺度和方法论问题和三维重建:SLAM的粒度和工程化问题 .大规模三维场景重建的尺度增大,因此相对于整个重 ...

  7. THREE.js代码备份——canvas_ascii_effect(以AscII码显示图形)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js - ASCII Ef ...

  8. Eclipse(含STS)安装插件/软件、更新

    安装方式 Eclipse安装插件的三种方式 直接复制安装 离线下载好插件,通常去这个插件的官网去找,就是在线安装的地址?如testng可以去http://beust.com/eclipse即http: ...

  9. 基于MATLAB的语音信号处理

    一.图形界面设计 1.新建GUI界面 2.新建空白页 3.命名为"yydsp",打开界面 4.拖放控件 5.按预定功能修改界面 6.填写Callback函数 未填写前的代码: fu ...

  10. 在 CentOS 7 上设置 grub2

    在 CentOS 7 上设置 grub2 1. 开机选单是自动创建出来的 请勿尝试手动编辑开机选单,因为它是按照 /boot/ 目录内的文件自动创建出来的.然而你可以调整 /etc/default/g ...