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 题目链接:http://codeforces.com/problemset/problem/660/A

题意:一个数组里面任意相邻的两个数互质,则数组为互质数组。添加最少的数使得这个数组为互质数组。输出添加的数的个数和添加之后
的数组。 思路:1和任意数都互质。

代码:
#include<bits/stdc++.h>
using namespace std;
__int64 a[],sign[];
__int64 gcd(__int64 x,__int64 y)
{
__int64 t;
if(x<y)
{
t=x;
x=y;
y=t;
}
while(y)
{
t=x%y;
x=y;
y=t;
}
return x;
}
int main()
{
int i,n;
int ans=;
memset(sign,,sizeof(sign));
scanf("%d",&n);
a[]=;
for(i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
if(a[i]>=&&gcd(a[i],a[i-])!=)
{
ans++;
sign[i]=;
}
}
cout<<ans<<endl;
for(i=; i<=n; i++)
{
if(sign[i]==) cout<<""<<" ";
if(i!=n) cout<<a[i]<<" ";
}
cout<<a[n]<<endl;
return ;
}

Codeforces 660A. Co-prime Array 最大公约数的更多相关文章

  1. codeforces 660A A. Co-prime Array(水题)

    题目链接: A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input stand ...

  2. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  3. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  4. CodeForces 660A Co-prime Array

    水题.放个1就可以了.暴力的找数字也是很快的. #include<cstdio> #include<cstring> #include<cmath> #includ ...

  5. Educational Codeforces Round 11A. Co-prime Array 数学

    地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...

  6. Educational Codeforces Round 21 D.Array Division(二分)

    D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  7. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  8. 【CodeForces 624D/623B】Array GCD

    题 You are given array ai of length n. You may consecutively apply two operations to this array: remo ...

  9. Codeforces 408 E. Curious Array

    $ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...

随机推荐

  1. 【原】解决Debug JDK source 无法查看局部变量的问题方案(重新编译rt.jar包)

    一.问题阐述 首先我们要明白JDK source为什么在debug的时候无法观察局部变量,因为在jdk中,sun对rt.jar中的类编译时,去除了调试信息,这样在eclipse中就不能看到局部变量的值 ...

  2. RabbitMQ 端口号解析

    转自:https://www.cnblogs.com/liuxingke/articles/9889517.html 端口号解析 12345 - 4369 (epmd), 25672 (Erlang ...

  3. IdUDPServer中文汉字乱码 及IdTCPClient

    官网 http://www.indyproject.org/docsite/html/frames.html?frmname=topic&frmfile=TIdTCPServer_OnExec ...

  4. delphi c++builder JSON 生成与解析 例子

    json,System.JSON,REST.JSON JSON有两种数据结构,对象和数组. 对象在js中表示为“{}”括起来的内容,数据结构为 {key:value,key:value,...} 数组 ...

  5. JS 时间 获取 当天,昨日,本周,上周,本月,上月

    调用 setTimeRange (2); function  setTimeRange (v) { var fmt = 'YYYY-MM-DD HH:mm'; var now = new Date() ...

  6. Mybatis知识(3)

    1.JDBC编程有哪些不足之处,MyBatis是如何解决这些问题的? ① 数据库链接创建.释放频繁造成系统资源浪费从而影响系统性能,如果使用数据库链接池可解决此问题. 解决:在SqlMapConfig ...

  7. 【OpenPose-Windows】运行OpenposeDemo.exe 如何保存图像运行结果及关节点信息

    跑过很多次openposeDemo了,不管是video.Webcam还是Images,都是运行结果一闪而过,然而我们所要的肯定不是只看一下运行结果就完事的,很多情况下,我们都希望能够把运行结果的图像. ...

  8. Technology, globalisation and the squeeze on good jobs

    Technology, globalisation and the squeeze on good jobs技术与全球化冲击好工作“Highest stock market EVER! Jobs ar ...

  9. Git reset head revert 回滚

    Overview 涉及Git一些日常操作 :) 基础知识 <Pro Git>至少了解branch,commit的概念,及基本的原理 Git常用魔法 存档:master代码回滚方法 我是QA ...

  10. 作业:WordCount--实现字符数,单词数,行数的统计

    1. Gitee 地址 https://gitee.com/fyxiaobai/wordcount 2. PSP表格 PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning ...