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. Asp.net MVC4 Step by Step (2)-参数数据的传递

    首先创建一个表单,不同于WebForm,框架提供了一系列HMTL帮助方法来生成HTML标签. 下面创建一个Create.cshtml为文件名的视图. <h2> Create Auction ...

  2. 团队作业-Beta版本发布

    这个作业属于哪个课程  <课程的链接>            这个作业要求在哪里 <作业要求的链接> 团队名称 Three cobblers 这个作业的目标 Beta版本发布报 ...

  3. HTML基础知识总结(一)

    概述       HTML是将内容和内容显示形式结合在一起的语言,它对于内容显示形式的控制,主要是通过标签(元素)的属性,由于它对“内容显示形式”存在着很多的弊端,所以之后就出现了CSS,CSS就相当 ...

  4. DNN结构演进History—CNN-GoogLeNet :Going Deeper with Convolutions

    抄袭了一片文章,进行少量修改:http://www.gageet.com/2014/09203.php       作者:Christian Szegedy( google )  刘伟(北卡罗来纳  ...

  5. Visual Basic for Application

    Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'The note of Visual Basic for Applicati ...

  6. C# 前一个数是后一个数的父级

    private void button2_Click(object sender, EventArgs e) { var str = "1 2 3 4 5 6 7 8 9 10 11 12 ...

  7. Visual Studio 2015 开发 Linux 和树莓派 程序的 C++环境

    可以创建 树莓派 和 linux控制台应用. 创建后的 readme , 有各个设置的说明 你需要输入你虚拟主机, 编译环境linux虚拟机  的简单配置,另外, 4月5日的版本 如果 你的linux ...

  8. BZOJ 1984月下“毛景树” LCT维护边权 + 下传标记

    Description 毛毛虫经过及时的变形,最终逃过的一劫,离开了菜妈的菜园. 毛毛虫经过千山万水,历尽千辛万苦,最后来到了小小的绍兴一中的校园里.爬啊爬~爬啊爬~~毛毛虫爬到了一颗小小的“毛景树” ...

  9. 验证:java 主线程在子线程结束后才会结束

    package com.idealisan.test; /** * Hello world! * */ public class App { public static void main( Stri ...

  10. MySQL创建临时表

    drop TEMPORARY table if EXISTS temp_table; create TEMPORARY table temp_table( id int not null, usern ...