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

题意:增加最少的正整数  使得序列相邻的数都互质

题解: 原序列中 若相邻的不互质 就把1放到中间 构成新序列

 #include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#define ll __int64
using namespace std;
int n;
int a[];
map<int,int> mp;
int ans;
void init()
{
mp.clear();
ans=;
for(int i=;i<=n-;i++)
{
if(__gcd(a[i],a[i+])==)
{
ans++;
mp[i]=;
}
}
}
int main()
{ scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
init();
printf("%d",n--ans);
printf("\n%d",a[]);
for(int i=;i<=n;i++)
{
if(mp[i-]==)
printf(" 1 %d",a[i]);
else
printf(" %d",a[i]);
}
cout<<endl;
return ;
}

Educational Codeforces Round 11 A的更多相关文章

  1. Educational Codeforces Round 11 C. Hard Process 前缀和+二分

    题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[ ...

  2. Educational Codeforces Round 11

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

  3. Educational Codeforces Round 11 E. Different Subsets For All Tuples 动态规划

    E. Different Subsets For All Tuples 题目连接: http://www.codeforces.com/contest/660/problem/E Descriptio ...

  4. Educational Codeforces Round 11 D. Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

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

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

  6. Educational Codeforces Round 11 B. Seating On Bus 水题

    B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...

  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 B

    Description Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of th ...

  9. Educational Codeforces Round 11 _D

    http://codeforces.com/contest/660/problem/D 这个题据说是很老的题了 然而我现在才知道做法 用map跑了1953ms: 题目大意 给你n个点的坐标 求这些点能 ...

随机推荐

  1. Python正则表达式-基础

    Python正则表达式-基础 本文转载自昔日暖阳,原文地址:http://www.osheep.cn/4806.html python使用正则,需要先引入re模块 import re 匹配符 单个字符 ...

  2. 嵌入式linux系统移植(一)

    内容:   交叉编译环境   bootloader功能子系统   内核核心子系统   文件系统子系统要点:  搭建交叉编译环境  bootloader的选择和移植  kernel的配置.编译.移植和调 ...

  3. Unicode控制字符

    Unicode控制字符就是特殊的Unicode字符 控制字符转义代码对照表 Unicode-控制字符 ‎LRM ‏RLM ‍ZWJ ‌ZWNJ ‪LRE ‭LRO ‮RLO ‬PDF NADS  ...

  4. WPF中,如何将绑定源设置到单件实例

    原文:WPF中,如何将绑定源设置到单件实例  WPF中,如何将绑定源设置到单件实例                                       周银辉 大概两个月前,曾有位朋友问我:如 ...

  5. ReentrantLock类的hasQueuedPredecessors方法和head节点的含义

    部分启发来源自文章:Java并发编程--Lock PART 1 1.如果h==t成立,h和t均为null或是同一个具体的节点,无后继节点,返回false.2.如果h!=t成立,head.next是否为 ...

  6. js学习日记-常用正则符号参考

    预定义类 量词 贪婪.惰性.支配性量词 前瞻 边界 RegExp是全局对象,RegExp.$1...$9是全局属性.当执行任意正则表达式匹配操作时,JavaScript会自动更新全局对象RegExp上 ...

  7. Django admin源码剖析

    单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. ...

  8. Python 3基础教程28-内置函数

    本文介绍Python中的内置函数,Python中有很多内置的,功能强大的函数,可以帮我们解决很多问题,有些方法,根本不需要你去再次编写实现函数,你直接调用就可以.在这之前,需要介绍下,如何在windo ...

  9. github 初始化操作小记

     Git作为一种越来越重要的工具,github又如此流行,现在就简单记录一下git的基础操作,希望能帮助大家快速体验入门! 1 查看本地是否存在”公钥”和”私钥” 如果没有,则执行: ssh-keyg ...

  10. 验证码 java实现的程序

    makeCheckcode.java package pic; import java.awt.Color; import java.awt.Font; import java.awt.Graphic ...