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. tail命令使用

    1.tail命令 命令的主要用途是将指定的文件的最后部分输出到终端,如果该文件有更新,tail会自己主动刷新. 2.tail语法 tail [ -f ] [ -c Number | -n Number ...

  2. python入门——Anaconda安装

    初学Python,可以选择python原始的IDE,但原始的IDE在使用过程中需要自己安装各种包,个人觉得初学者不需要将时间花在这些上面,而是应该直接学习python程序,这些比较杂的事情可以在以后的 ...

  3. Java输出日历写法

    package TestString_2; import java.text.ParseException;import java.util.Calendar;import java.util.Gre ...

  4. App间常用的五种通信方式

    1.URL Scheme 2.Keychain 3.UIPasteboard剪切板 4.UIDocumentInteractionController 5.local socket 详见: 转自:ht ...

  5. java_hdfs之读写文件

    package hdfsTest.answer.hdfs; import java.io.IOException; import java.net.URI; //import java.net.URL ...

  6. Unity3d工具方法小集

    1.获取垂直水平方向上的输入: float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = I ...

  7. cachel-control

    nodejs: res.set('Cache-Control', 'public, max-age=31557600'); express全局设置:       app.use(express.sta ...

  8. MQTT 开源代理mosquitto的网络层封装相当sucks

    最近学习MQTT协议,选择了当前比较流行的MQTT Broker “mosquitto”,但是在阅读代码过程中发现其网络底层库封装的相当差劲. 对于MQTT协议的变长头长度的读取上,基本上采取每次一个 ...

  9. C++ STL容器——stack用法介绍

    stack是一种容器适配器,专门设计用于在LIFO上下文中操作(后进先出),其中元素仅从容器的一端插入和删除. 容器适配器,而不是一种容器. 它是容器适配器是指,只要支持一系列方法的容器(empty, ...

  10. PAT——乙级1006:换个格式输出整数&乙级1021:个位数统计&乙级1031:查验身份证

    1006 换个格式输出整数 (15 point(s)) 让我们用字母 B 来表示“百”.字母 S 表示“十”,用 12...n 来表示不为零的个位数字 n(<10),换个格式来输出任一个不超过 ...