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学习之控制流2

    配置环境:python 3.6 python编辑器:pycharm 代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- # 控制流语句: # if语句 ...

  2. Python学习手册之函数和模块

    在上一篇文章中,我们介绍了 Python 的控制结构,现在我们介绍 Python 函数和模块. 查看上一篇文章请点击:https://www.cnblogs.com/dustman/p/9976234 ...

  3. ABAP CDS ON HANA-(12)ODATA Service

    Create a CDS view and we have the view type as ‘BASIC’ view To publish this as oData, add the annota ...

  4. [Python 3.X]python练习笔记[2]-----用python实现七段数码管显示年月日

    #SevenDigitsDrawV2.py import turtle import time def drawGap(i):#绘制数码管间隔 turtle.penup() turtle.fd(i) ...

  5. CDH-5.9.2整合spark2

    1.编写目的:由于cdh-5.9.2自带spark版本是spark1.6,现需要测试spark2新特性,需要整合spark2, 且spark1.x和spark2.x可以同时存在于cdh中,无需先删除s ...

  6. Hibernate-ORM:03.Hibernate主键生成策略

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 此篇博客简单记录五种常用的主键生成策咯: 不同的主键生成策略,生成的sql语句,以及hibernate的操作都 ...

  7. fastlane自动化打包ipa并发布到firim或者蒲公英

    1.打开终端,确保Xcode Command Line Tools 安装了最新版 xcode-select --install 2.安装fastlane sudo gem install -n /us ...

  8. android中的文件(图片)上传

    android中的文件(图片)上传其实没什么复杂的,主要是对 multipart/form-data 协议要有所了解. 关于 multipart/form-data 协议,在 RFC文档中有详细的描述 ...

  9. ionic 入口禁止加载其他页面

    .state('memberOrders', { prefetchTemplate: false, url: '/memberOrders', templateUrl: '/MemberOrders' ...

  10. Linux环境搭建系列之sorl服务器的安装部署

    http://blog.csdn.net/upxiaofeng/article/details/51425732