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. 显式锁(四)Lock的等待通知机制Condition

       任意一个Java对象,都拥有一组监视器方法(定义在根类Object上),主要包括:wait( ).wait(long timeout).notify().notifyAll()方法:这些方法与关 ...

  2. tornado-简单的服务器

    安装tornado pip install tornado 安装sqlalchemy 1.大概代码的解释 import tornado.ioloop #开启循环,等待访问 import tornado ...

  3. 自动化运维工具 SaltStack 在云计算环境中的实践

    http://www.talkwithtrend.com/Article/218473

  4. 1.java生成随机不重复10位字符串

    package org.changneng.util; import java.util.Random; public class A { public static void main(String ...

  5. WP runtime 获取cookie

    HttpBaseProtocolFilter httpBaseProtocolFilter = new HttpBaseProtocolFilter(); HttpCookieManager http ...

  6. web 项目手机页面不允许缩放

    https://blog.csdn.net/ljw_jiawei/article/details/80421240

  7. 集中化管理平台Saltstack安装配置

    salt是一个异构平台基础设置管理工具(虽然我们通常只用在Linux上),使用轻量级的通讯器ZMQ,用Python写成的批量管理工具,完全开源,遵守Apache2协议,与Puppet,Chef功能类似 ...

  8. 各种java面经资源

    面试的角度诠释Java工程师(一) 面试的角度诠释Java工程师(二) Java面试参考指南(一) Java面试参考指南(二) 阿里面试回来,想和Java程序员谈一谈 面试心得与总结—BAT.网易.蘑 ...

  9. Docker查看关联容器的卷宗在本机的存储位置

    docker inspect -f {{.Volumes}} volume1

  10. python 写hive循环脚本

    要一个月的数据 一次跑一周的数据 ,建表用插入数据的方法: import os, sys reload(sys); sys.setdefaultencoding( "utf-8" ...