Educational Codeforces Round 11 A
1 second
256 megabytes
standard input
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.
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.
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.
3
2 7 28
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的更多相关文章
- Educational Codeforces Round 11 C. Hard Process 前缀和+二分
题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[ ...
- Educational Codeforces Round 11
A. Co-prime Array http://codeforces.com/contest/660/problem/A 题意:给出一段序列,插进一些数,使新的数列两两成互质数,求插最少的个数,并输 ...
- 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 ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...
- Educational Codeforces Round 11 B. Seating On Bus 水题
B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...
- 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 ...
- 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 ...
- Educational Codeforces Round 11 _D
http://codeforces.com/contest/660/problem/D 这个题据说是很老的题了 然而我现在才知道做法 用map跑了1953ms: 题目大意 给你n个点的坐标 求这些点能 ...
随机推荐
- Python tips(
(此文是在实际工程中遇到的一些小问题,给予解决和整理.解决方法大多来自网上零散的文章.有一个系统化的Python问题解决方案,来自<Python 3 学习笔记>雨痕著,其中对Python的 ...
- R语言学习笔记(六): 列表及数据框的访问
List R语言中各组件的名称叫做标签(tags),访问列表有3种方法: j$salary 通过标签名字访问,只要不引起歧义,可以只写出前几个字母. j[['sal']] 夹在两个中括号时引号里的标签 ...
- shell重温---基础篇(shell数组&数组操作)
上篇博客已经分析重温了shell的运行方式以及其中的变量还有字符串,之后按照套路就是数组方面了,废话不多说,直接进入正题哈.(小白笔记,各位看官勿喷...) bash shell呢,支持一位数 ...
- python 推导式的用法
推导式看了不少,可每次都有新发现 例子1:返回满足条件为真,否则为假 try_list = [1, 2, 3, 4, 5] # 前2种一样, [a > 3 for a in b] [True i ...
- ORB-SLAM (四)tracking跟踪解析
初始化完成后,对于相机获取当前图像mCurrentFrame,通过跟踪匹配上一帧mLastFrame特征点的方式,可以获取一个相机位姿的初始值:为了兼顾计算量和跟踪鲁棒性,处理了三种模型: 1. Tr ...
- mysql 5.7.19 zip版本 windows安装步骤
请注意此文档用于msyql5.7系列及以后版本(包括最新 mysql 8.0.11)zip版本windows下的安装1.下载mysql省略2.解压mysql到D:\Program Files\mysq ...
- python语句和语法
python语句和语法 python程序结构: 1.程序由模块构成. 2.模块包含语句. 3.语句包含表达式. 4.表达式建立并处理对象. python的语法实质上是有语句和表达式组成的.表达式处理对 ...
- 电子取证-破解给定的SAM文件
给你一个SAM文件,如何提取出登录密码? SAM文件 ① LMHASH Administrator:500:0182bd0bd4444bf867cd839bf040d93b:c22b315c040ae ...
- Java 集合学习--ArrayList
一.ArrayList 定义 ArrayList 是一个用数组实现的集合,支持随机访问,元素有序且可以重复. ①.实现 List 接口 List接口继承Collection接口,是List类的顶层接口 ...
- CPU拓扑结构
本篇旨在认识一下以下三种CPU拓扑结构分别是什么: Symmetric multiprocessing (SMP) Non-uniform memory access (NUMA) Simultane ...