A. Co-prime Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 kelements to it.

If there are multiple answers you can print any one of them.

Example
input
3
2 7 28
output
1
2 7 9 28

给你一个序列在不改变原来相对顺序的情况下插入最少个数使得该序列相邻数均为互质,只要插入的个数最少,答案可以不唯一。本来以为会WA,没想到过了。

代码:

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
inline int gcd(const int &a,const int &b)
{
return b?gcd(b,a%b):a;
}
int main (void)
{
int n,i,j,ans,t;
while (cin>>n)
{
vector<int>vec;
map<int,int>pos;
for (i=0; i<n; i++)
{
cin>>t;
vec.push_back(t);
}
for (i=0; i<n-1; i++)
{
if(gcd(vec[i],vec[i+1])!=1)
{
for (j=2; j<=100000000; j++)
{
if(gcd(vec[i],j)==1&&gcd(vec[i+1],j)==1)//map记录每个位置是否要放入和放入的值
{
pos[i]=j;
break;
}
}
}
}
cout<<pos.size()<<endl;
for (i=0; i<n; i++)
{
if(pos.find(i)!=pos.end())
cout<<vec[i]<<" "<<pos[i];
else
cout<<vec[i];
if(i==n-1)
cout<<endl;
else
cout<<" ";
}
}
return 0;
}

Educational Codeforces Round 11——A. Co-prime Array(map+vector)的更多相关文章

  1. Educational Codeforces Round 59 (Rated for Div. 2) (前四题)

    A. Digits Sequence Dividing(英文速读) 练习英语速读的题,我还上来昏迷一次....只要长度大于2那么一定可以等于2那么前面大于后面就行其他no 大于2的时候分成前面1个剩下 ...

  2. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  3. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  4. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  5. Codeforces Round #603 (Div. 2) E. Editor(线段树)

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...

  6. Codeforces Round #617 (Div. 3) String Coloring(E1.E2)

    (easy version): 题目链接:http://codeforces.com/contest/1296/problem/E1 题目一句话就是说,两种颜色不同的字符可以相互换位, 问,对这字符串 ...

  7. 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 ...

  8. Educational Codeforces Round 11

    A. Co-prime Array http://codeforces.com/contest/660/problem/A 题意:给出一段序列,插进一些数,使新的数列两两成互质数,求插最少的个数,并输 ...

  9. Educational Codeforces Round 11 C. Hard Process 二分

    C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...

随机推荐

  1. 四、filter和find函数的区别

    filter(): filter函数会返回data中为true那项的数组(即查询符合条件的数据) eg:data.filter((f)=>{ if(f[name]===item[name]){ ...

  2. MFC:DISP_FUNCTION 参数

    /*#include <afxdisp.h>DISP_FUNCTION( theClass, pszName, pfnMember, vtRetVal, vtsParams )参数:the ...

  3. openstack keystone修改horizon密码

    命令行修改密码:token在/etc/keystone/keystone.conf中的一个admin_token export OS_SERVICE_TOKEN=165a1766c12a497b8fb ...

  4. WPF DataGridCheckBoxColumn需要点两次才能修改checkbox状态

    如题,如果必须要用DataGridCheckBoxColumn使用一下方式就可以解决需要点击两次才能改状态的问题 <DataGridCheckBoxColumn> <DataGrid ...

  5. 修改broadcom 4322无线网卡ID教程,不再显示第三方无线网卡

    本帖最后由 hellokingabc 于 2016-1-11 03:07 编辑 黑苹果已经基本完美,但是无线网卡总是出现问题,经常断网,经过搜索,原因在于无线网卡在OSX系统下显示为第三方无线网卡,只 ...

  6. 如何用VS2017用C++语言写Hello world 程序?

    1,首先,打开VS2017. 2,左上角按文件——新建——项目,或按ctrl+shift+n. 3,按照图片里的选,选完按“确定”. 4,右键“源文件”,再按添加——新建项. 5,剩下的就很简单了,只 ...

  7. OI算法复习

    搜集一些算法,赛前背一背有好处的 转自各大网站 前排感谢:hzwer.风了咕凉 前辈...Orz 快速读入: int read() { ,f=;char ch=getchar(); ;ch=getch ...

  8. 理解JWT的使用场景和优劣

    理解JWT的使用场景和优劣 淘楼小能手 百家号04-2816:20 经过前面两篇文章<JSON Web Token - 在Web应用间安全地传递信息><八幅漫画理解使用JSON We ...

  9. Windows7设置局域网文件共享

    首先要实现共享必须设置共享的机器与访问共享的机器在同一个工作组中. 右键桌面上的计算机图标=>属性 如果不一样的话,就需要点击[更改设置] 右键要共享的文件或者文件夹,点击[共享]打开共享标签: ...

  10. Linux-缓存服务

    Memcached 基本操作 解释 命令 安装 yum install memcached 启动 memcached -d -l -m -p 停止 kill pid 查看某个端口是否通:telnet ...