题目链接:

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 k elements 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 题意: 给一个数组,问插入多少个数字才能使相邻的两个数互质; 思路: 暴力找呗,找到的放队列里,最后输出不就好了; AC代码:
/*
2014300227 660A - 7 GNU C++11 Accepted 15 ms 2188 KB
*/

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+4;
typedef long long ll;
const double PI=acos(-1.0);
int n,a[3000];
int gcd(int x,int y)
{
if(y==0)return x;
return gcd(y,x%y);
}
queue<int>qu;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int num=0;
for(int i=1;i<n;i++)
{
qu.push(a[i]);
if(gcd(a[i],a[i+1])>1)
{


qu.push(1);
num++;
}
}
qu.push(a[n]);
printf("%d\n",num);
while(!qu.empty())
{
printf("%d ",qu.front());
qu.pop();
}


return 0;
}

 

codeforces 660A A. Co-prime Array(水题)的更多相关文章

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

  2. CF451B Sort the Array 水题

    Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...

  3. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  4. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  5. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  6. Codeforces Beta Round #37 A. Towers 水题

    A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...

  7. hdu 5532 Almost Sorted Array (水题)

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  8. codeforces 677A A. Vanya and Fence(水题)

    题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. CodeForces 690C1 Brain Network (easy) (水题,判断树)

    题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...

  10. Codeforces - 1194B - Yet Another Crosses Problem - 水题

    https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...

随机推荐

  1. PropertiesTest

    import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; public clas ...

  2. 如何修改eclipse的默认字符集和修改中文乱码

    转载,以供以后学习.谢谢 有时候 java代码,导入eclipse中会出现 乱码的问题,通过修改字符集就可以解决. 看下面图片演示过程. 发表在 使用教程 | 标签为 eclipse, 乱码 | 留下 ...

  3. Linux环境变量PS1配置

    1. 说明: 在Shell下,我们能够拥有更加色慘斑斓的提示行信息.这能够通过改变bash的$PS1环境变量还设置,如以下就是提示行的一种: user@host$ root用户的提示是这种: user ...

  4. AndroidX86模拟器Genymotion的一些使用和另一款Andy模拟器

    命令行启动虚拟机 当我们下载安装好,可以通过命令行运行指定名字模拟器 D:\ProgramFiles\Genymobile\Genymotion\player  --vm-name "Sam ...

  5. java 动态实现接口

    package com.yhouse.modules.daos; public interface IUserDao { public String getUserName(); public Str ...

  6. easyUI中 datagrid 格式化日期

    $('#List').datagrid({ url: '@Url.Action("GetList")', width:SetGridWidthSub(10), methord: ' ...

  7. 多媒体开发之---h264 取流解码实现

    解码器在解码时,首先逐个字节读取NAL的数据,统计NAL的长度,然后再开始解码. nal_unit( NumBytesInNALunit ) {  /* NumBytesInNALunit为统计出来的 ...

  8. 初识python轻量web框架flask

    1.使用pip安装Python包 大多数Python包都使用pip实用工具安装,使用pyvenv创建的虚拟环境会自动安装pip. 1.使用pip安装Flask(其它Python包同理) pip ins ...

  9. @Bean 和@ Component的区别

    @Component auto detects and configures the beans using classpath scanning whereas @Bean explicitly d ...

  10. Hibernate性能优化

    1.性能是与具体的项目挂钩的,并不是对于A项目某种优化方法好就适用于B项目.性能需要不断的测试检验出来的.....(废话) 2.session.clear()方法的使用,通常session是有缓存的 ...